SpringMVC context:annotation-config 配置

<context:annotation-config />

做用:使在spring容器中注册的bean生效(已存在的bean)spring

@Autowire,光一个注释是不起做用的,须要在Spring容器中声明来自bean自动检测处理器BeanPostProcessor接口相关的实现的bean-->AutowiredAnnotationBeanPostProcessor bean ;数据库

 

@Resource 、@PostConstruct、@PreDestroy等注解须要声明CommonAnnotationBeanPostProcessor bean,也实现自BeanPostProcessorspringboot

@Resource: 不用说都知道做用服务器

@PostConstruct: 做用在非静态的void()方法,该方法会在服务器加载Servle的时候运行,而且只会被服务器执行一次,做用时间点在构造函数以后执行,init()方法以前执行mvc

@PreDestroy: 做用在非静态的void()方法,该方法在destroy()方法执行执行以后执行函数

 

@PersistenceContext须要声明PersistenceAnnotationBeanPostProcessor beanui

@PersistenceContext实体对象管理器,须要额外配置persistence.xml来助攻,接收数据库查询出来的A数据,依据配置文件的辅助,调整A数据成B数据实体结果spa

 

@Required须要声明RequiredAnnotationBeanPostProcessor bean.net

@Required做用在setter上的注入xml

 

<context:annotation-config />隐式向Spring容器提供以上4个的BeanPostProcessor bean,使上述的注解生效

 

从springboot回来学spring mvc xml方式,某些不认识的配置感受就是了解大体其功能特色,对于其中的原理,基本接口实现,一些不认识的注解等等未知,感受这辈子都不会再见到,意会便可

----------------------------------------------------------------------

相关文章
相关标签/搜索