use-default-filters的用法

<context:component-scan base-package="com.atguigu.atcrowdfunding.*" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
context:component-scan里面的use-default-filters默认值为true,使用默认的过滤器,会自动扫描带有@Component、@Repository、@Service和@Controller的类。
上面的配置表示扫描时会将Controller排除,而如果在use-default-filters默认值为true的时候配置context:include-filter

(注意是include,而如果是exclude-filter

那么则会报错,在idea会显示No matching beans found,因为默认过滤器关闭了,又没有指定include-filter,扫描不到bean)是没有意义的,因为

默认是扫描所有的类,所以一般上面的配置会在spring中配置,将Controller排除,交给springMVC容器管理。
<context:component-scan base-package="com.atguigu.atcrowdfunding.*" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

而这段配置则仅仅扫描Controller,通常在springMVc配置文件中配置,在"use-default-filters="false"的情况下,只扫描Controller,但是如果没有配置"use-default-filters="false",那么

事务是会加不上去的因为springMVC容器也会注入service类,根据就近原则,默认是会使用springMVC中的service,那么在spring中配置的事务就不起作用了。

(初学者,有误请指正,谢谢)

转载于:https://www.cnblogs.com/alicebob/p/9864839.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值