Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 배열
- 메서드
- JavaScript
- 기본
- oracle
- Android
- HTML
- 국제화
- JSP
- 에러페이지
- paint
- Eclips
- Spring
- 메소드
- Java
- layout
- mybatis
- 전화걸기
- 생성자
- struts2
- 어노테이션
- 안드로이드
- OGNL
- 클래스
- 이클립스
- 예외처리
- Graphic
- 오버로딩
- AWT
- Menu
Archives
- Today
- Total
note
Spring @Qualfier 어노테이션 본문
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 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-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- -RequiredAnnotationBeanPostProcessor :@Required 사용시 -AutowiredAnnotationBeanPostProcessor : @Autowired 사용시 -CommonAnnotationBeanPostProcessor : @Resource,@PostConstruct , @PreDestroy 사용시 -ConfigurationClassPostProcessor : @Configuration 사용시 아래 태그로 대체 가능 <context:annotation-config /> --> <!-- @Autowired 어노테이션 사용시 필수적으로 설정 --> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean id="monitor" class="madvirus.spring.chap04.homecontrol.SystemMonitor" /> <bean id="sender" class="madvirus.spring.chap04.homecontrol.SmsSender" /> <!-- @Qualifer 어노테이션을 이용한 자동 설정 제한 --> <bean id="systemMonitor" class="madvirus.spring.chap04.homecontrol.SystemMonitor2" /> <bean id="recorder" class="madvirus.spring.chap04.homecontrol.Recorder"> <qualifier value="main" /> </bean> </beans>
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
'JSP > Spring' 카테고리의 다른 글
Spring @PostConstruct / @PreDestroy 어노테이션과 라이프 사이클 (0) | 2012.03.02 |
---|---|
Spring @Resource 어노테이션 (0) | 2012.03.02 |
Spring @Autowired 어노테이션 (0) | 2012.02.29 |
Spring @Required 어노테이션(Annotation) (0) | 2012.02.29 |
Spring 국제화 (0) | 2012.02.29 |