spring中的context:include-filter和context:exclude-filter的区别
2018-03-19 09:17
323 查看
1.在spring-mvc.xml中有以下配置:
<!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.zcjy.os.edu.controller" use-default-filters="false" >
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /></context:component-scan>可以看出要把最终的包写上,而不能这样写base-package="com.zcjy.os.edu.”。这种写法对于include-filter来讲它都会扫描,而不是仅仅扫描@Controller。哈哈哈,这点需要注意。他一般会导致一个常见的错误,那就是事务不起作用,补救的方法是添加use-default-filters=”false”。
2. 在主容器中(applicationContext.xml)有如下配置:
<!-- 配置扫描注解,不扫描@Controller注解 -->
<context:component-scan base-package="com.zcjy.os.edu">
<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>
可以看到,他是要扫描com.zcjy.os.edu包下的所有子类,不包含@Co
4000
ntroller。对于exculude-filter不存在包不精确后都进行扫描的问题。
<!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.zcjy.os.edu.controller" use-default-filters="false" >
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /></context:component-scan>可以看出要把最终的包写上,而不能这样写base-package="com.zcjy.os.edu.”。这种写法对于include-filter来讲它都会扫描,而不是仅仅扫描@Controller。哈哈哈,这点需要注意。他一般会导致一个常见的错误,那就是事务不起作用,补救的方法是添加use-default-filters=”false”。
2. 在主容器中(applicationContext.xml)有如下配置:
<!-- 配置扫描注解,不扫描@Controller注解 -->
<context:component-scan base-package="com.zcjy.os.edu">
<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>
可以看到,他是要扫描com.zcjy.os.edu包下的所有子类,不包含@Co
4000
ntroller。对于exculude-filter不存在包不精确后都进行扫描的问题。
相关文章推荐
- spring中的context:include-filter和context:exclude-filter的区别
- spring中的context:include-filter和context:exclude-filter的区别
- spring中的context:include-filter和context:exclude-filter的区别
- spring中的context:include-filter和context:exclude-filter的区别
- Spring 注解 <context:component-scan> 子标签 <context:exclude-filter > 和 <context:include-filter>区别
- spring中的context:include-filter和context:exclude-filter的区别
- spring中的context:include-filter和context:exclude-filter的区别
- spring中的context:include-filter和context:exclude-filter的区别
- spring的context:exclude-filter 与 context:include-filter
- <context:include-filter>和<context:exclude-filter>区别
- 分析:<context:component-scan>中<context:include-filter>与<context:exclude-filter>的区别
- Spring配置文件中<context:include-filter>和<context:exclude-filter>
- include-filter和exclude-filter的区别
- 从头认识Spring-2.7 自动检测Bean(3)-过滤器<context:exclude-filter/>
- 【SpringMVC】<context:include-filter>和<context:exclude-filter>使用时要注意的地方
- 【SpringMVC】<context:include-filter>和<context:exclude-filter>使用时要注意的地方 在Spring MVC中的配置中一般会遇到这两个标签,作为<
- 【SpringMVC】<context:include-filter>和<context:exclude-filter>
- Spring笔记--context:include-filter
- context:exclude-filter 与 context:include-filter 转
- spring的自动扫描里面的include-filter,exclude-filter