码迷,mamicode.com
首页 > 编程语言 > 详细

Spring中的context:annotation-config作用

时间:2015-01-12 22:19:46      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

<context:annotation-config/>

他的作用是隐式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor、 RequiredAnnotationBeanPostProcessor 这4个BeanPostProcessor.

如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。

如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下:

<bean class="org.springframework.beans.factory.annotation.
AutowiredAnnotationBeanPostProcessor "/> 

如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。同样,传统的声明方式如下:

<bean class="org.springframework.beans.factory.annotation.
RequiredAnnotationBeanPostProcessor"/>

Spring中的context:annotation-config作用

标签:

原文地址:http://www.cnblogs.com/lomomiao/p/4219686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!