SpringMVC (<context:include-filter>和<context:exclude-filter>的使用)

eg:

1、现在给定一个项目包的结构:

 com.yk.controller

 com.yk.service

2、在SpringMVC.XML有以下的配置:

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

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

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

</context:component-scan>

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

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

 

2)<context:component-scan base-package="com.yk"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>

这样的意思 不包括@controller

posted on 2016-09-11 22:21  xiaohehe2  阅读(4789)  评论(1编辑  收藏  举报

导航