spring mvc 注解扫描问题 ,扫描不到controller, use-default-filters="false"

本文解决了SpringMVC项目中无法扫描到Controller的问题。原因是<context:component-scan>中的use-default-filters设置为false,未配置include-filter或exclude-filter导致默认不扫描@Controller注解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天搭了个spring mvc项目,怎么也扫描不到controller,最后发现问题在use-default-filters="false"上面,乱copy出的问题

(默认值是true,它的作用就是扫描一些相关的注解,包括了@controller,@Component,@Service,@Repository等,)

  <context:component-scan base-package="com.example" use-default-filters="false">

  </context:component-scan>


如果配置为false,会在下面寻找类似配置include-filter和exclude-filter,一个黑名单方式,一个白名单方式,上面两个都没配,所以默认不扫描
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

 

转载于:https://www.cnblogs.com/binlin1987/p/7052975.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值