项目框架
Spring + Spring-MVC
情况说明
- 在配置spring的配置文件applicationContext.xml的时候,需要剔除对@Controller的扫描
- 在配置springmvc的配置文件springmvc.xml的时候,需要剔除其他的,只扫描@Controller
一些文章和网站说是为了各司其职,划清界限。
配置文件
applicationContext.xml
<context:component-scan base-package="com">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
spring-mvc.xml
<context:component-scan base-package="com" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
问题
- 如果我两个配置文件都不剔除任何配置,都扫描所有Bean然后加载,那么是会造成容器中有2个Bean吗,如果是这样会有什么影响?
- 有的配置会详细指定特别多的包,然后用逗号隔开,那我这样的直接从com开始,这样范围特别大,那会造成启动缓慢吗?
spring已经考虑到这点了,包扫描的时候,会做校验的
