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