Spring组件扫描<context:component-scan/>使用详解
来源:互联网 发布:windows开机不显示壁纸 编辑:程序博客网 时间:2024/06/06 12:42
1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入。<context:include-filter type="regex" expression=".service.*"/>
</context:component-scan>
<!-- 注解注入 -->
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.liantuo.hotel.common.service.impl" />
<context:component-scan base-package="com.liantuo.hotel.common.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.service" />
<context:component-scan base-package="com.liantuo.hotel.app.service.ibatis" />
2.下面是引用spring framework开发手册中的一段话“
Spring 2.5引入了更多典型化注解(stereotype annotations):或
@Component
、@Service
和@Controller
。@Component
是所有受Spring管理组件的通用形式;而@Repository
、@Service
和@Controller
则是@Component
的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。也就是说,你能用@Component
来注解你的组件类,但如果用@Repository
、@Service
@Controller
来注解它们,你的类也许能更好地被工具处理,或与切面进行关联。例如,这些典型化注解可以成为理想的切入点目标。当然,在Spring Framework以后的版本中, @Repository
、@Service
和@Controller
也许还能携带更多语义。如此一来,如果你正在考虑服务层中是该用@Component
还是@Service
,那@Service
显然是更好的选择。同样的,就像前面说的那样,@Repository
已经能在持久化层中进行异常转换时被作为标记使用了。”3.有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
4.<context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
如:<context:component-scan base-package="com.xhlx.finance.budget" >
</context:component-scan>
5.filter标签在Spring3有五个type,如下:
Filter TypeExamples ExpressionDescriptionannotationorg.example.SomeAnnotation符合SomeAnnoation的target classassignableorg.example.SomeClass指定class或interface的全名aspectjorg.example..*Service+AspectJ语法regexorg\.example\.Default.*Regelar Expressioncustomorg.example.MyTypeFilterSpring3新增自訂Type,实作org.springframework.core.type.TypeFilter 0 0
- spring组件扫描<context:component-scan/>详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- Spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解 .
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- JNI详解:C/C++与JAVA通信机制
- centos中apache连接postgresql提示SQLSTATE[08006] [7] could not connect to server: Permission denied
- ios状态栏的颜色修改
- 给jquery-validation插件添加控件的验证回调方法
- VC编译选项md /mdd /ml /mt/mtd
- Spring组件扫描<context:component-scan/>使用详解
- Date、String和Timestamp类型转换
- inotify的一个简单程序
- linux下安装boost
- LOGO图片详细说明(作业)
- Django学习笔记+官方网站
- android【资源汇总分享】Android开发资源汇总之一
- CSS 实现加载动画之七-彩环旋转
- Oracle中通过Function,存储过程,触发器,调用实现解析Clob字段中存在的xml字符串