一、spring-context*.xml 合并到 spring-mvc.xml 的方法
spring-servlet.xml 中加入 <import resource="ApplicationContext.xml" />
ApplicationContext.xml 中把其它的xml文件import進來
web.xml
SpringMVC核心分發器 加入參數 <param-value>classpath:spring-mvc.xml</param-value>
不加載 <param-value>classpath*:/spring-context*.xml</param-value>
controller/service等都在mvc中加載
<context:component-scan base-package="com.mweb.**.controller" />
<context:component-scan base-package="com.mweb.**.service" />。。。。需要加載的@Component等
加入:
<aop:aspectj-autoproxy proxy-target-class="true" />
二、spring-context*.xml / spring-mvc.xml 分開加載掃描的方法
web.xml 中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring-context*.xml</param-value> </context-param>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 必須加入才行 </listener> <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value> </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
spring-mvc.xml 中:
<context:component-scan base-package="com.mweb.**.controller" /> 掃描 controller
<aop:aspectj-autoproxy /> aop 參考下面的也行
- <aop:aspectj-autoproxy proxy-target-class="true">
- <aop:include name="controllerAspect"/> @Aspect聲明的類
- </aop:aspectj-autoproxy>
spring-context.xml中:
<context:component-scan base-package="com.mweb.**.extension,
com.mweb.**.service,
com.mweb.base.aspect,
com.mweb.base.shiro.realm" />
<aop:aspectj-autoproxy proxy-target-class="true" />這樣就可以了
posted on 2016-11-22 09:44
liufx 閱讀(3273)
評論(0) 編輯 收藏 所屬分類:
調試錯誤記錄