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 |
Tags
- 이클립스
- paint
- 기본
- 국제화
- 배열
- Graphic
- 생성자
- JavaScript
- Eclips
- struts2
- Android
- Menu
- 안드로이드
- AWT
- 예외처리
- Spring
- HTML
- mybatis
- JSP
- 메서드
- 어노테이션
- OGNL
- Java
- 클래스
- 전화걸기
- 메소드
- layout
- 에러페이지
- oracle
- 오버로딩
Archives
- Today
- Total
note
Spring @Required 어노테이션(Annotation) 본문
전제 조건
applicationContext.xml 에
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
applicationContext.xml
Camera.java
package madvirus.spring.chap04.homecontrol;
import org.springframework.beans.factory.annotation.Required;
public class Camera {
private int number;
public Camera(){
}
@Required
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "Camera [number=" + number + "]";
}
}
Main.java
package madvirus.spring.chap04.homecontrol;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
String[] configLocations = new String[] { "applicationContext.xml" };
ApplicationContext context = new ClassPathXmlApplicationContext(
configLocations);
Camera camera = context.getBean("camera1", Camera.class);
System.out.println(camera);
}
}
Camera.java
setNumber에 반드시 데이터를 넘기라는 표현
Spring에서만 사용할 수 있는 방법
짧은 표현 방법
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />를
<context:annotation-config /> 로 대처해도 실행화면은 같다
Camera [number=1]
※※※※※※※※※※※
-RequiredAnnotationBeanPostProcessor :@Required 사용시
-AutowiredAnnotationBeanPostProcessor : @Autowired 사용시
-CommonAnnotationBeanPostProcessor : @Resource,@PostConstruct , @PreDestroy 사용시
-ConfigurationClassPostProcessor : @Configuration 사용시
<context:annotation-config />
로 모두 대처 가능함
<context:annotation-config />
로 모두 대처 가능함
'JSP > Spring' 카테고리의 다른 글
Spring @Qualfier 어노테이션 (0) | 2012.02.29 |
---|---|
Spring @Autowired 어노테이션 (0) | 2012.02.29 |
Spring 국제화 (0) | 2012.02.29 |
Spring 프로퍼티 타입을 이용한 의존 관계 자동 설정 (0) | 2012.02.29 |
Spring 프로퍼티 이름을 이용한 의존 관계 자동 설정 (0) | 2012.02.29 |