spring和springMVC配置文件中的扫描包如何配置

我的项目大概文件路径:

然后进入主题:
spring的配置文件名称为applicationContext.xml
springMVC的配置文件名称为dispatcherServlet-servlet.xml

1.spring的配置文件中需要将Controller的注解排除掉。也就是排除@Controller。需要扫描到service和dao层的注解
可以用以下这种方式:

	<context:component-scan base-package="com.dancer.crudr">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>

2.springMVC的配置文件中需扫描Controller的注解。也就是扫描@Controller
可以用以下这种方式:

	<context:component-scan base-package="com.dancer.crud" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>

接下来具体分析:

//这个是格式,照抄就完了
<context:component-scan></context:component-scan>  
//这个是要扫描的包,我是没填写完整路径
 base-package
//这个默认是true,意思就是会自动对 @Component、@ManagedBeuse-default-filters="true"an、@Named注解的Bean进行扫描。
  反之把他改为false则不对@Component、@ManagedBeuse-default-filters="true"an、@Named注解的Bean进行扫描
use-default-filters
//这个是排除的意思
exclude-filter
//这个是包含的意思
include-filter


spring分析:

	//自动扫描com.dancer.crudr包下的所有注解
	<context:component-scan base-package="com.dancer.crudr">
		//但是排除Controller的注解
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		//exclude-filter:排除,得到除Controller以外的注解
	</context:component-scan>

springMVC分析:

	//不会自动扫描com.dancer.crudr包下的所有注解,因为use-default-filters改为false
	<context:component-scan base-package="com.dancer.crud" use-default-filters="false">
		//获取Controller的注解
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		//use-default-filters:不会自自动扫描
		//include-filter:包含,得到Controller的注解
	</context:component-scan>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值