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 |
【推荐】腾讯云新用户域名抢购1元起,抓紧抢购
· 摩拜发布共享单车与城市可持续发展报告:上海起最早、抗霾最积极
· 保温杯+枸杞:究竟是中年人的孤单,还是年轻人的狂欢?
· 滴滴与美团将在哪些领域火力全开?
· 盖茨J.P.摩根健康大会演讲:生命科学研究可挽救数百万人的生命
· 微博云剪2.0版本上线 2 分钟制作一个短视频
» 更多新闻...
· 以操作系统的角度述说线程与进程
· 软件测试转型之路
· 门内门外看招聘
· 大道至简,职场上做人做事做管理
2014-02-27 工作组模式下专用队列(Private Queue)如何引用远程队列路径