Spring的组件装配


<context:annotation-config/>

       annotation-config将会在Spring容器注册AutowiredAnnotationBeanPostProcessor(该bean可以自动装配具有@Autowired、@Resource、@Inject等注解的属性),而不需要我们再使用<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>这种方式手动注入该bean了。除了上述的那个bean,还有CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor以及RequiredAnnotationBeanPostProcessor这三个BeanPostProcessor。

<context:compnent-scan/>

       component-scan会对包进行扫描,实现注解驱动 Bean 定义。即将@Controller标识的类的bean注册到容器中,不过在@Component语义基础上细化后的@Repository,@Service和@Controller也同样可以。
       同时component-scan还启用了注解驱动自动注入的功能(即还隐式地在内部注册了AutowiredAnnotationBeanPostProcessor和CommonAnnotationBeanPostProcessor)。因此当使用<context:component-scan/> 后,除非需要使用PersistenceAnnotationBeanPostProcessor和RequiredAnnotationBeanPostProcessor两个Processor的功能(例如 JPA 等),否则就可以不需要配置<context:annotation-config/>。
<context:component-scan base-package="org.zero.spring4.test" />  

<mvc:annotation-driven/>

       annotation-driven会向Spring容器中注册 DefaultAnnotationHandlerMapping、AnnotationMethodHandlerAdapter,解决@Controller注解的使用前提配置,即 HandlerMapping 能够知道谁来处理请求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值