还有一个请高手说下自己的理解:
<context:component-scan base-pack="com.test">
<context:include-filter type="annotation" expression="org.springframework.mvc.Controller"/>
</context:component-scan>
我的理解是:自动扫描包com.test或者子包下面含有@Component,@Controller,@Respotory,@Service这样注解的类,并注册进容器bean中
filter是扫描含有@Controller注解的类,然后注册到bean容器中。(但是上面不是package扫描了么,要这个filter有什么用?多此一举么)求高手解释
<context:component-scan base-pack="com.test">
<context:include-filter type="annotation" expression="org.springframework.mvc.Controller"/>
</context:component-scan>
我的理解是:自动扫描包com.test或者子包下面含有@Component,@Controller,@Respotory,@Service这样注解的类,并注册进容器bean中
filter是扫描含有@Controller注解的类,然后注册到bean容器中。(但是上面不是package扫描了么,要这个filter有什么用?多此一举么)求高手解释
解决方案 »
- 急求:图片上传并预览的问题
- 用JSP查询数据库信息然后显示如何做
- 初学lucene问题
- js获取控件 在控件后面插入(innerHtml)
- jspsmart upload 接收 utf-8中文时乱码
- 页面上有一个日期,传到FormBean里面用什么类型的值?
- jsp中写的脚本代码如何获得本页内的内容
- tomcat+jdk的问题??请大家帮帮忙..
- Servlet高手快请进,小问题,100分答谢,分数小事情,程序显人情
- win2k professional下运行JSP,请推荐JDK版本与服务器软件
- 侠哥们。。hibernate如何执行sql,进行登录处理。。
- document.all.WebBrowser如何在ie下打印,求详解!!!
using "stub" repositories instead.
<beans>
<context:component-scan base-package="org.example">
<context:include-filter type="regex" expression=".*Stub.*Repository"/>
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
</beans>可以看看官方说明。
我看的是Spring in Action 3rd。可能是我英语不好把,感觉还没有区分加filter和不加filter的区别。不加了,我知道<context:component-scan>这个是根据base-pack扫描,然后注册到容器中加了filter他是什么情况,如果仅仅扫过滤的,那么其他的需要注入的bean呢?如果这种情况下其他的注解class也被扫,那么还要include-filter做什么。
<context:annotation-config/>
<context:component-scan base-package="**.**.**" >
<context:execute-filter type="annotation" expression="org.springframework.stereotype.Controller"
</context:conmponet-scan>
context:include-filter对于include,我的理解是,除了扫描base-package包下面的子类,还扫描expression后面的包。
context:exclude-filter对于exclude,我认为,即使expression后面的包在base-package下面,也不扫描。是这样吗?
context:include-filter对于include,我的理解是,除了扫描base-package包下面的子类,还扫描expression后面的包。
context:exclude-filter对于exclude,我认为,即使expression后面的包在base-package下面,也不扫描。是这样吗?
是的,因为你在base-package定义了一个包所在的路径,可是如果你需要扫描其它的类或者啥的,可是又不在你base-package包里面,那么就需要 include-filter
相反的,exclude就是去除你不需要扫描的class。比如@Controller注释的,因为这个需要在SpringMVC的配置文件配置的