note

Spring @Qualfier 어노테이션 본문

JSP/Spring

Spring @Qualfier 어노테이션

투한 2012. 2. 29. 17:43








applicationContext.xml



	

	
	
	
	
	
	
	


	
	
	
		
	



SystemMonitor2.java
package madvirus.spring.chap04.homecontrol;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class SystemMonitor2 {
	private MessageSender sender;
	@Autowired
	@Qualifier("main")
	private Recorder recorder;

	public SystemMonitor2(MessageSender sender) {
		this.sender = sender;
	}
	public SystemMonitor2() {
	}
	public MessageSender getSender() {
		return sender;
	}
	@Autowired
	public void setSender(MessageSender sender) {
		this.sender = sender;
	}
	public Recorder getRecorder() {
		return recorder;
	}
	public void setRecorder(Recorder recorder) {
		this.recorder = recorder;
	}	
}


Recorder.java
package madvirus.spring.chap04.homecontrol;

public class Recorder {

}



Main03.java
package madvirus.spring.chap04.homecontrol;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main03 {
	public static void main(String[] args) {
		String[] configLocations = new String[] { "applicationContext.xml" };
		ApplicationContext context = new ClassPathXmlApplicationContext(
				configLocations);
		
		SystemMonitor2 monitor = context.getBean("systemMonitor",SystemMonitor2.class);
		System.out.println(monitor.getSender());
		System.out.println(monitor.getRecorder());
	}
}


aa
aa




@Qualifier("main")

recorder 안에 main이라고 명시 되어있어야 받겠다라는 표현
즉 Autowired에서 한단계더 강력하게 데이터를 걸러 내겠다는(?)
 

부가적인 설정 제어를 위한 







실행화면(Main03.java)

madvirus.spring.chap04.homecontrol.SmsSender@c1918e

madvirus.spring.chap04.homecontrol.Recorder@3b26f3