spring与springMVC配置扫描的问题
生活随笔
收集整理的這篇文章主要介紹了
spring与springMVC配置扫描的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
首先,如果不配置事務在哪里掃描都是可以的,但是這是不可能的,所以掃描的時候就需要有先后的順序。
順序:spring負責除controller層之外所有注解的掃描,將controller層的掃描放到MVC的配置文件中。
spring配置文件:
<context:component-scan base-package="com" use-default-filters=false> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>springMVC配置文件:
<context:component-scan base-package="com" use-default-filters=false> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan>按照如上順序,springMVC只掃描controller然后其他的都交由spring來掃描
?
ps:當base-package包含controller層、service層、Repository層時,需要設置use-default-filters,否則會掃描所有的注解,不區分。
轉載于:https://my.oschina.net/mrfu/blog/1504010
總結
以上是生活随笔為你收集整理的spring与springMVC配置扫描的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java的三种代理模式简述
- 下一篇: android studio ndk-b