spring 配置 context:component-scan使用说明

1、spring配置文件如下

<context:component-scan base-package="com.hesvit">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>

xml配置说明:
<context:component-scan/>上下文组件扫描
1.1“com.hesvit”表示扫描com.hesvit包下的所有java类
1.2
<context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller" />
表示扫描com.hesvit包下的类,但排除@controller注解的

1.3 如果是 <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
表示扫描com.hesvit包下的只包含@controller注解的

1.4 context:component-scan中use-default-filters
在context:component-scan可以添加use-default-filters,spring配置中的use-default-filters用来指示是否自动扫描带有@Component、@Repository、@Service和@Controller的类。默认为true,即默认扫描。

###其他
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
的作用请参考以下链接:经常用于异常处理

http://jinnianshilongnian.iteye.com/blog/1866350

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值