Closed mysterin closed 5 years ago
@Autowired
AutowiredAnnotationBeanPostProcessor
@Resource
@PostConstruct
@PreDestroy
CommonAnnotationBeanPostProcessor
@PersistenceContext
PersistenceAnnotationBeanPostProcessor
@Required
RequiredAnnotationBeanPostProcessor
<context:annotation-config />
<context:component-scan /> 包含了 <context:annotation-config /> 功能, 同时还支持 @Component, @Service, @Repository, @Controller 注解, 通过扫描对应包向容器注册对应 bean.
<context:component-scan />
@Component
@Service
@Repository
@Controller
相当于注册了 DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 两个 bean, 即解决了@Controller 注解的使用前提配置.
DefaultAnnotationHandlerMapping
AnnotationMethodHandlerAdapter
@Autowired
需要AutowiredAnnotationBeanPostProcessor
的支持;@Resource
,@PostConstruct
,@PreDestroy
需要CommonAnnotationBeanPostProcessor
的支持;@PersistenceContext
需要PersistenceAnnotationBeanPostProcessor
的支持;@Required
需要RequiredAnnotationBeanPostProcessor
的支持; 所以,<context:annotation-config />
就是向容器隐式注册上面 4 个 BeanPostProcessor.<context:component-scan />
包含了<context:annotation-config />
功能, 同时还支持@Component
,@Service
,@Repository
,@Controller
注解, 通过扫描对应包向容器注册对应 bean.相当于注册了
DefaultAnnotationHandlerMapping
和AnnotationMethodHandlerAdapter
两个 bean, 即解决了@Controller
注解的使用前提配置.