@Required : 메소드를 통해 값을 주도록 강요함. (property 안적어줬을 때 에러)
@Required 사용하려면
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
위의 형태는 너무 길어서 context 사용(동일한 효과)
<context:annotation-config />
@Autowired : 내부적으로 Setter가 생성. Bean의 자동 삽입을 위해 사용. (type 으로 매핑)
@Autowired를 사용하려면
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
위의 형태는 너무 길어서 context 사용(동일한 효과) 아래의 한줄을 적어주고 객체 생성에만 충실하면 된다!
<context:annotation-config />
@Qualifier : @Autowired를 name 으로 매핑하고 싶을 때 함께 사용.
@Resource : Bean의 자동 삽입을 위해 사용. (name 으로 매핑)
@Scope : 스프링에서 관리하는 Bean은 Singleton 이 디폴트.
- Singleton : 싱글톤으로 객체를 한 개만 생성
- Prototype : 사용자 요청별로 별개의 객체를 생성
@Component : 객체 생성. Bean 생성.
@Component을 사용하려면
<context:component-scan base-package="패키지명" />
context:component-scan 만 있으면 context:annotation-config 도 필요 없다!
@Service : 해당 클래스가 Service Bean 임을 지정.
@Repository : 해당 클래스가 Repository Bean 임을 지정. (DB 관련 내용은 Repository 사용)
@PostConstruct : 생성자 수행 후 수행. JDK가 지원.
@PreDestroy : 응용 프로그램 종료 직전에 수행되어 마무리 작업. JDK가 지원. 내부적으로 수행되어 콘솔에 출력 안됨.
@Value : 초기치로 부여할 때 사용. 사용 시 @Autowired를 생성자에 써줘야 함.
스프링에서는 기본적으로 클래스 선언부 위에 @Component가 붙어 있으면 스프링 빈으로 생성.
그러나 보통 실무인 경우에 다음과 같이 한다.
- Controller 클래스 에는 @Controller
- Service 클래스 에는 @Service
- DAO 클래스 에는 @Repository
참고로! 버전업 될 때 마다 새로운 어노테이션(Annotation) 계속 등장