-
[Spring] 어노테이션 기반 컨테이너 설정Spring 2019. 8. 22. 01:16
_각괄호 선언 대신 바이트코드 메타 데이터를 사용하여 컴포넌트를 와이어링하는 방식으로 xml 셋업을 대체하는 어노테이션 기반 설정이 제공
_빈 와이어링 기술을 위해 xml을 사용하는 대신, 개발자는 연관된 클래스, 메소드 또는 필드 선언에 어노테이션을 사용
As mentioned in Example: The RequiredAnnotationBeanPostProcessor, using a BeanPostProcessor in conjunction with annotations is a common means of extending the Spring IoC container.
For example, Spring 2.0 introduced the possibility of enforcing required properties with the @Required annotation.
Spring 2.5 made it possible to follow that same general approach to drive Spring’s dependency injection. Essentially, the @Autowired annotation provides the same capabilities as described in Autowiring Collaborators but with more fine-grained control and wider applicability.
Spring 2.5 also added support for JSR-250 annotations, such as @PostConstruct and @PreDestroy.
Spring 3.0 added support for JSR-330 (Dependency Injection for Java) annotations contained in the javax.inject package such as @Inject and @Named. Details about those annotations can be found in the relevant section.
As always, you can register them as individual bean definitions, but they can also be implicitly registered by including the following tag in an XML-based Spring configuration (notice the inclusion of the context namespace):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
</beans>
스프링 공식 문서'Spring' 카테고리의 다른 글
[Spring] 스프링 프레임워크의 IoC 컨테이너와 빈 (0) 2019.08.21 [Spring] 스프링 REST서버에서 에러를 처리하는 방법 (0) 2019.06.03 [Spring] @Resource, @Inject, @Autowired (0) 2019.05.26 [Spring] 간단한 웹 MVC 프로젝트 (0) 2019.05.12 [Spring] 스프링 웹 MVC 개요 (0) 2019.05.11 댓글