티스토리 뷰

bean 객체에는 다양한 속성들이 존재한다. 이번 포스팅에서는 그 중에서 객체 로드에 관련된 속성 3가지를 정리하려고 한다. 

 

그렇게 복잡한 내용이 아니므로 3개의 속성 모두 한번에 설명하겠다.


1. init-method: bean 객체가 처음 생성될 때, 호출할 메서드를 지정할 수 있는 속성

2. destroy-method: bean 객체가 소멸할 때, 호출할 메서드를 지정할 수 있는 속성

3. lazy-init: true 로 설정되면, bean 객체가 프로젝트가 로드될 때 생성되는 것이 아닌 실제로 사용되는 시점에 생성되도록 하는 속성

 

◎LgTV

package polymorphism;

public class LgTV implements TV{

	public LgTV() {
		// TODO Auto-generated constructor stub
	}
	
	public void initMethod() {
		System.out.println("LgTV --- 초기화 메서드");
	}
	
	public void destroyMethod() {
		System.out.println("LgTV --- 소멸 메서드");
	}
	
	@Override
	public void powerOn() {
		System.out.println("LgTV --- 전원 켜기");
	}
	
	@Override
	public void powerOff() {
		System.out.println("LgTV --- 전원 끄기");
	}
	
	@Override
	public void volumeUp() {
		System.out.println("LgTV --- 소리 키우기");
	}
	
	@Override
	public void volumeDown() {
		System.out.println("LgTV --- 소리 줄이기");
	}

}

 

◎applicationContext.xml

<?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 = "lg" class = "polymorphism.LgTV" init-method="initMethod" destroy-method="destroyMethod" lazy-init="true">
    </bean>

</beans>

Comments