springmvc配置说明:context:component-scan

本文介绍了SpringMVC中如何使用context:component-scan进行组件扫描,并通过include-filter和exclude-filter来精确控制哪些注解的类会被扫描并注册为bean。

springmvc配置说明:context:component-scan

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

以上,自动扫描com.springmvc下的@Component @Controller @Service等这些注解的类,把这些类注册为bean。
由于扫描力度过大,对不需要的注解类不进行扫描,所以引入context:include-filter和context:exclude-filter。

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

以上,这里不需要扫描@Service注解类,所以引入exclude-filter,对不需要扫描的@Service注解类不进行扫描。

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

以上,这里只需要扫描@Controller注解类,所以引入include-filter,只对@Controller注解类进行扫描。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值