SpringMVC ( 的使用)


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM