spring配置中<context:annotation-config> 和 <context:component-scan>区别
来源:互联网 发布:java 数据字典表设计 编辑:程序博客网 时间:2024/05/17 22:34
详细介绍
<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解。
<context:component-scan>除了具有<context:annotation-config>的功能之外,<context:component-scan>还可以在指定的package下扫描以及注册javabean 。
1、<context:annotation-config/>配置作用:
他的作用是式地向 Spring 容器注册AutowiredAnnotationBeanPostProcessor 、CommonAnnotationBeanPostProcessor 、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
注册这4个
例如:
如果你想使用@Autowired注解,那么就必须事先在
<bean
如果想使用@ Resource
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBea
如果想使用
<bean
一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>的简化配置方式,自动帮你完成声明。
不过,呵呵,我们使用注解一般都会配置扫描包路径选项
<context:component-scan
原文章连接地址
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- Spring MVC: <context:annotation-config> 和 <context:component-scan>区别
- Spring <context:annotation-config>和<context:component-scan>区别
- Spring <context:annotation-config> 和 <context:component-scan>区别
- Spring配置中<context:annotation-config> VS <context:component-scan>
- spring配置里<context:annotation-config>和<context:component-scan>区别
- context:annotation-config配置和context:component-scan配置
- Spring <context:annotation-config/> 和 <context:component-scan>
- <context:annotation-config/>和context:component-scan的区别
- <context:annotation-config> 和 <context:component-scan>的区别
- <context:annotation-config> 和 <context:component-scan>的区别
- context:component-scan和context:annotation-config的区别
- <context:annotation-config> 和 <context:component-scan>的区别
- <context:annotation-config> 和 <context:component-scan>的区别
- <context:annotation-config>和<context:component-scan>
- Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别
- 2015-5-31:实验室第六天
- 多线程相关知识点总结--黄彬
- Spring+SpringMVC+MyBatis+Maven框架整合
- andropid事件分发拦截机制
- PC开发工程师的出路
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- Oracle限权管理
- 我有10个职场经验,价值100万,但今天免费|咪蒙
- 笔记9列表生成器
- 判断某一区域是否为空
- 【Leetcode】之Add Binary
- 图书馆管理系统
- 【2016.5.21普及组模拟】约数国王(A king)
- Python DM Learning Intro