Spring组件自动扫描功能

来源:互联网 发布:js string startswith 编辑:程序博客网 时间:2024/05/23 01:58

首先需要在applicationContext中添加<context:component-scan/>
1)扫描bean的注解,代替xml中bean元素的定义。
     @Service  用于service业务组件
     @Control  用于Action控制组件
     @Respository 用于dao数据访问组件 
     @Conmponent  用于其他组件
注:bean组件扫描到容器后,默认名字为类名(首字母小写)
如果需要自定义名称可以使用service(“id名”)
2)依赖注入的注解标记
    @Resource  按名称    @Resource(name=”id名”)
     @Autowired  按类型 
  
      @Resource 
      @Qualifier(“id名”)
3)其他注解
     @Scope  等价于<bean scope=””>

0 0
原创粉丝点击