博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring组件扫描<context:component-scan/>使用详解
阅读量:7039 次
发布时间:2019-06-28

本文共 1296 字,大约阅读时间需要 4 分钟。

1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入。

<!-- 注解注入 -->
<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" />
@Component(组件)@Service(服务层)@Controller(控制层)@Repository(数据库访问层)
3.有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
<context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
<context:component-scan base-package="com.xhlx.finance.budget" >

<context:include-filter type="regex" expression=".service.*"/>

</context:component-scan>

 

filter标签在Spring3有五个type,如下:

Filter Type

Examples Expression Description
annotation org.example.SomeAnnotation 符合SomeAnnoation的target class
assignable org.example.SomeClass 指定class或interface的全名
aspectj org.example..*Service+ AspectJ语法
regex org\.example\.Default.* Regelar Expression
custom org.example.MyTypeFilter Spring3新增自訂Type,实作org.springframework.core.type.TypeFilter

转载地址:http://osxal.baihongyu.com/

你可能感兴趣的文章
第十八回  基础才是重中之重~开发人员应学会用throw
查看>>
Swift -- 中文版两大官方文档汇总
查看>>
U3D调用7z解压文件
查看>>
Windows移动开发(二)——闭关修炼
查看>>
java 获取 path
查看>>
小盆友给谷歌写封信 老爸获一周假期
查看>>
Ubuntu安装配置Qt环境
查看>>
LBS 与 GPS 定位之间的区别
查看>>
Android调用系统的Activity、ContentProvider、Service、Broadcast Receiver
查看>>
对象池模式
查看>>
Android学习笔记(四十):Preference的使用
查看>>
ByteArrary(优化数据存储和数据流)
查看>>
围住神经猫,朋友圈瞬间爆红是如何炼成的?
查看>>
HDUoj-------(1128)Self Numbers
查看>>
huffman编码——原理与实现
查看>>
php curl获取网页内容乱码和获取不到内容的解决方法
查看>>
【JavaScript】关于prototype
查看>>
普通Jquery的ajax判断重复和formvalidator的ajaxValidator区别
查看>>
ovs处理openflow消息的流程
查看>>
精品素材:WALK & RIDE 单页网站模板下载
查看>>