Spring与SpringMVC重复扫描问题

在SpringMVC.XML有以下的配置:

《!--扫描@controller注解--》

<context:component-scan base-package="com.xxx.controller">

   <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />

</context:component-scan>

把最终的包写上,而不能这样写base-package="com.xxx"。这种写法对于:include-filter来讲它都会扫描。而不是仅仅扫描@controller

如果这样,一般会导致一个常见的错误---事务不起作用。解决的方法:添加:use-default-filters=”false”

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

  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 

</context:component-scan>

 在Spring.xml配置

<context:component-scan base-package="com.xxx"> 

  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />

</context:component-scan>

这样的意思 不包括@controller

猜你喜欢

转载自www.cnblogs.com/fg-fd/p/9916682.html
今日推荐