<context:annotation-config /> 与<context:component-scan />
来源:互联网 发布:php 编译 mysqli 编辑:程序博客网 时间:2024/05/01 15:45
Spring容器默认禁止用注解配置。所以在使用注解的自动配置之前我们需要在applicationContext.xml中添加:
<context:annotation-config />
但是我们一般会使用:
<context:component-scan />
来代替,因为前者包含了后者,并且能够允许Spring自动检测Bean和定义Bean.
如:
<context:component-scan base-package="com.xingguo.account" />
能够自动扫面com.xingguo.account包下能够自动注册为Spring Bean的类。
Spring3 支持集中不同的自动装配的注解:
- Spring自带的@Autowired注解
- JSR-330的@Inject注解
- JSR-250的@Resource注解
推荐使用 JSR-330的@Inject注解。
为自动检测标注Bean: - @Component
- @Repository
- @Service
- @Controller
- @Named
其中@Controller一般用于SpringMVC中的Controller上。其他四个一样。不过大家习惯于,把@Service用于service上,@Repository用于DAO上。这些都可以用@Named替代。
0 0
- <context:annotation-config /> 与<context:component-scan />
- <context:component-scan>与 <context:annotation-config>
- spring <context:component-scan/>与<context:annotation-config/>
- Spring IOC <context:annotation-config>与<context:component-scan/>
- <context:annotation-config> & <context:component-scan>
- <context:annotation-config>和<context:component-scan>
- <context:component-scan>,<context:annotation-config/>,<mvc:annotation-scan/>
- <mvc:annotation-driven/>,<context:annotation-config/>,<context:component-scan/>详解
- <mvc:annotation-driven/> <context:annotation-config/> <context:component-scan>
- Spring <context:annotation-config/> <context:component-scan/>与<mvc:annotation-driven />
- <context:component-scan base-package=""> <context:annotation-config>
- Spring <context:annotation-config/> 、<context:component-scan>解说
- Spring <context:annotation-config/> 和 <context:component-scan>
- Spring MVC: <context:annotation-config> 和 <context:component-scan>区别
- context:annotation-config配置和context:component-scan配置
- <context:annotation-config/>和context:component-scan的区别
- <context:annotation-config> vs <context:component-scan> 的区别
- Difference between <context:annotation-config> vs <context:component-scan>
- 关于iOS的多线程处理方式
- python处理HTML转义字符
- 正则表达式案例
- MyEclipse + Tomcat项目重命名
- 两个超长正整数的加法
- <context:annotation-config /> 与<context:component-scan />
- 网站权重提高技巧
- Java反射中Method类invoke方法的用法
- DirectX3D游戏开发一 第一个DirectX3D项目
- Jcrop(头像裁剪工具)
- HDU 2072 单词数
- MPMoviePlayerController 添加自定义控件
- 使用memcache存储数据
- SAP Basis: 从SAP GUI杀死进程