spring提供了Component-scan来扫描组件
这两篇文章是学习是参考的http://stackoverflow.com/questions/10725192/exclude-subpackages-from-spring-autowiring
http://blog.sina.com.cn/s/blog_57769b7b0100tt5x.html
http://913.iteye.com/blog/1280808
基本上应该这样安排扫描项目applicationContext这种扫描所有除了Controller之外的组件,然后WebApplicationContext的servlet-name-servlet.xml值扫苗Controller
所以applicationContext中
<context:component-scan base-package="com.szd">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
WebApplicationContext中
<!-- load controller only -->
<context:component-scan base-package="com.szd">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
这里不能将Component也exclude,因为Component是所有注解类型的父类,如果这样注释的话,所有的注解都被注释了。