spring配置中<context:annotation-config> 和 <context:component-scan>区别
来源:互联网 发布:烟台青少年编程培训 编辑:程序博客网 时间:2024/06/01 22:31
<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>诠释及区别
- Excel在统计分析中的应用—第八章—假设检验-单个正态总体方差的假设检验
- TCP 三次握手vsTCP 四次握手
- react入坑之列表和key(索引)
- React Native入门(十三)之组件的生命周期
- IntelliJ IDEA 学习笔记
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- dataGrid 删除行
- IndentationError: unindent does not match any outer indentation level
- 滑动变阻器改进AD输入电压(STM32)
- POJ 3292.Semi-prime H-numbers
- POJ1741 tree 【点分治】
- Python day2 总结
- postgresql操作
- Cmake “no cmake c_compiler could be found”,“无法打开输入文件”问题解决思路