Spring(DI)_02_04

2025. 1. 22. 17:48·Spring, Boot/기초 내용 정리

2025-01-22

 

 

 

 

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [person.xml]
INFO : org.springframework.context.support.GenericXmlApplicationContext - Refreshing org.springframework.context.support.GenericXmlApplicationContext@32cf48b7: startup date [Wed Jan 22 17:45:30 KST 2025]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@38102d01: defining beans [person1,person2,info]; root of factory hierarchy
이 름 >>> 유관순
주민번호 >>> 2025-0001
성 별 >>> 여성
나 이 >>> 19
연락처 >>> 010-2222-2222
INFO : org.springframework.context.support.GenericXmlApplicationContext - Closing org.springframework.context.support.GenericXmlApplicationContext@32cf48b7: startup date [Wed Jan 22 17:45:30 KST 2025]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@38102d01: defining beans [person1,person2,info]; root of factory hierarchy

 

package com.spring.di04;

import org.springframework.context.support.GenericXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
		
		GenericXmlApplicationContext container = 
				new GenericXmlApplicationContext("person.xml");
		
		PersonInfo person = (PersonInfo)container.getBean("info");
		
		// 비지니스 로직 호출
		person.getPersonInfo();
		
		container.close();
	}
}

 

package com.spring.di04;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Person {

	private String name;
	private String juminNo;
	private String gender;
	private int age;
	private String phone;
}

 

package com.spring.di04;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public class PersonInfo {

	private Person person;
	
	// 비지니스 로직
	public void getPersonInfo() {
		if (person != null) {
			System.out.println("이 름 >>> " + person.getName());
			System.out.println("주민번호 >>> " + person.getJuminNo());
			System.out.println("성 별 >>> " + person.getGender());
			System.out.println("나 이 >>> " + person.getAge());
			System.out.println("연락처 >>> " + person.getPhone());
		}
	}
}

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<!-- 인자생성자로 테이터 초기화 -->
	<bean id="person1" class="com.spring.di04.Person">
		<constructor-arg value="홍길동"/>
		<constructor-arg value="2025-0000"/>
		<constructor-arg value="남성"/>
		<constructor-arg value="27"/>
		<constructor-arg value="010-1111-1111"/>
	</bean>
	
	<!-- setter() 메서드로 데이터 초기화 -->
	<bean id="person2" class="com.spring.di04.Person">
		<property name="name" value="유관순"></property>
		<property name="juminNo" value="2025-0001"></property>
		<property name="gender" value="여성"></property>
		<property name="age" value="19"></property>
		<property name="phone" value="010-2222-2222"></property>
	</bean>
	
	<bean id="info" class="com.spring.di04.PersonInfo">
		<constructor-arg>
			<!-- person2 참조 -->
			<ref bean="person2"/>
		</constructor-arg>
	</bean>

</beans>

'Spring, Boot > 기초 내용 정리' 카테고리의 다른 글

Spring(MVC)_01_01  (0) 2025.01.22
Spring(DI)_02_05  (0) 2025.01.22
Spring(DI)_02_03  (0) 2025.01.21
Spring(DI)_02_02  (0) 2025.01.21
Spring(DI)_02_01  (0) 2025.01.21
'Spring, Boot/기초 내용 정리' 카테고리의 다른 글
  • Spring(MVC)_01_01
  • Spring(DI)_02_05
  • Spring(DI)_02_03
  • Spring(DI)_02_02
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Spring(DI)_02_04
상단으로

티스토리툴바