博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring过滤器组件自动扫描
阅读量:7120 次
发布时间:2019-06-28

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

在这个 ,您已经了解如何使Spring自动扫描您的组件。在这篇文章中,我们将展示如何使用组件过滤器自动扫描过程。

1.过滤组件 - 包含

参见下面的例子中使用Spring “过滤” 扫描并注册匹配定义“regex”,即使该类组件的名称未标注 @Component 。

DAO 层

package com.yiibai.customer.dao;public class CustomerDAO {	@Override	public String toString() {		return "Hello , This is CustomerDAO";	}	}

Service 层

package com.yiibai.customer.services;import org.springframework.beans.factory.annotation.Autowired;import com.yiibai.customer.dao.CustomerDAO;public class CustomerService {	@Autowired	CustomerDAO customerDAO;	@Override	public String toString() {		return "CustomerService [customerDAO=" + customerDAO + "]";	}		}

Spring 过滤

执行

package com.yiibai.common;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.yiibai.customer.services.CustomerService;public class App {    public static void main( String[] args )    {    	ApplicationContext context = 		new ClassPathXmlApplicationContext(new String[] {"Spring-AutoScan.xml"});    	CustomerService cust = (CustomerService)context.getBean("customerService");    	System.out.println(cust);    	    }}

输出

CustomerService [customerDAO=Hello , This is CustomerDAO]
在这个XML过滤中,所有文件的名称中包含 DAO 或 Service(*DAO.*, *Services.*) 单词将被检测并在 Spring 容器中注册。
2.过滤组件 - 不包含
另外,您还可以排除指定组件,以避免 Spring 检测和 Spring 容器注册。不包括在这些文件中标注有 @Service 。
不包括那些包含DAO这个词组文件名。
 
下载代码 – 
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/p/6367457.html,如需转载请自行联系原作者
你可能感兴趣的文章
前端重构实践(一) —— 性能优化
查看>>
Oracle 10g 问题集锦
查看>>
如何处理IE首页被篡改的问题
查看>>
思科网络设备模拟器GNS3与SecureCRT关联
查看>>
Activemq判断队列存活脚本(一)
查看>>
系统状态检测 及进程控制
查看>>
xen-tools创建虚拟机找不到root fs的解决办法
查看>>
IBM X3650 M4 服务器
查看>>
备份和归档的区别
查看>>
shell基础
查看>>
linux 文件类型 时间戳 ls bash特性四 文件查看命令 cp move echo
查看>>
如何在XenDesktop中映射USB设备
查看>>
Java并发编程 基础知识学习总结
查看>>
我又发现一个直接就能安装中文小红帽的方法
查看>>
ACM弱校ACMer A HDU1045Fire Net有感
查看>>
cxgrid实现分组统计和添加Footer
查看>>
刘敏华:2013年网络营销行业展望
查看>>
理解MySQL——架构与概念
查看>>
vsftpd虚拟用户
查看>>
ionic 幻灯指令 ion-slide-box
查看>>