首页 > 编程语言 > 详细

Spring文档苦读【5】【<context:annotation-config/>】

时间:2016-12-29 10:44:31      阅读:160      评论:0      收藏:0      [点我收藏+]

如何配置Spring注解

<?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
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config/>

</beans>

描述

上述配置,会隐式的配置一下PostProcessor,具体:AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor, 以及 RequiredAnnotationBeanPostProcessor。

并,如何你在DispatcherServlet对应的WebApplicationContext配置<context:annotation-config/>,其只会@Autowired,而不会检查Service下的注解。

AutowiredAnnotationBeanPostProcessor

声明@Autowired注解

CommonAnnotationBeanPostProcessor

声明@Resource、@PostConstruct、@PreDestroy等注解

PersistenceAnnotationBeanPostProcessor

声明@PersistenceContext注解

RequiredAnnotationBeanPostProcessor

声明@Required注解

关注

在我们使用注解时一般都会配置扫描包路径选项:

<context:component-scan base-package="pack.pack"/>

该配置项其实也包含了自动注入上述processor的功能,因此当使用<context:component-scan/>后,即可将<context:annotation-config/>省去。

摘录:http://www.cnblogs.com/iuranus/archive/2012/07/19/2599084.html

Spring文档苦读【5】【<context:annotation-config/>】

原文:http://www.cnblogs.com/may-cn/p/6231889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!