spring-ssm_webapp-mvc.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:mvc="http://www.springframework.org/schema/mvc"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-3.1.xsd
  9. http://www.springframework.org/schema/aop
  10. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  11. http://www.springframework.org/schema/mvc
  12. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
  13. <!-- 自动扫描指定包下的 @Controller 注解 -->
  14. <!-- 自动扫描指定包下的 @Controller 注解 -->
  15. <context:component-scan base-package="com.ssm">
  16. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  17. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
  18. </context:component-scan>
  19. <!-- <bean id="InitListener" class="com.ssm.common.InitListener" /> -->
  20. <mvc:interceptors>
  21. <!-- <mvc:interceptor>
  22. <mvc:mapping path="/**" />
  23. <mvc:exclude-mapping path="/resources/**" />
  24. <mvc:exclude-mapping path="/login" />
  25. <bean class="com.ssm.interceptor.LoginInterceptor" />
  26. </mvc:interceptor> -->
  27. <mvc:interceptor>
  28. <mvc:mapping path="/**" />
  29. <mvc:exclude-mapping path="/login" />
  30. <mvc:exclude-mapping path="/saveUser" />
  31. <mvc:exclude-mapping path="/deleteUser" />
  32. <mvc:exclude-mapping path="/resources/**" />
  33. <bean class="com.ssm.interceptor.MenuInterceptor" />
  34. </mvc:interceptor>
  35. </mvc:interceptors>
  36. <!-- 设置静态资源的访问映射 location 为静态资源所在项目中的存放路径, mapping 为使用者引用静态的路径 -->
  37. <mvc:resources location="/resources/" mapping="/resources/**" />
  38. <!-- <mvc:resources location="/upload/" mapping="/upload/**" /> -->
  39. <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  40. <property name="messageConverters">
  41. <list>
  42. <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
  43. <bean class="org.springframework.http.converter.StringHttpMessageConverter">
  44. <property name="writeAcceptCharset" value="false" /><!-- See SPR-7316 -->
  45. <!-- @ResponseBody 返回类型为String的中文编码问题 -->
  46. <property name = "supportedMediaTypes">
  47. <list>
  48. <value>text/html;charset=UTF-8</value>
  49. </list>
  50. </property>
  51. </bean>
  52. <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
  53. <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
  54. <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
  55. <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
  56. <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
  57. <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
  58. <bean class="org.springframework.http.converter.FormHttpMessageConverter" />
  59. </list>
  60. </property>
  61. </bean>
  62. <bean id="initConfig" class="com.ssm.common.SpringInitConfig"/>
  63. <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  64. <!-- <property name="maxUploadSize"><value>100000</value></property> -->
  65. <property name="defaultEncoding"><value>UTF-8</value></property>
  66. </bean>
  67. <!-- Spring AOP for authority -->
  68. <bean id="authorityAdvice" class="com.ssm.web.AuthorityAdvice"></bean>
  69. <bean id="pageNavigation" class="com.ssm.web.PageNavigation"></bean>
  70. <aop:config>
  71. <aop:pointcut id="lap"
  72. expression="execution(* com.ssm.controller.*.*(..)) or execution(* com.ssm.controller.*.*.*(..))" />
  73. <aop:aspect ref="authorityAdvice">
  74. <aop:around pointcut-ref="lap" method="aroundMethod" />
  75. </aop:aspect>
  76. <aop:aspect ref="pageNavigation">
  77. <aop:around pointcut-ref="lap" method="aroundMethod2" />
  78. </aop:aspect>
  79. </aop:config>
  80. <!-- 根据不同的请求返回不同的view -->
  81. <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  82. <!-- 设置为true以忽略对Accept Header的支持 -->
  83. <property name="ignoreAcceptHeader" value="true" />
  84. <!-- 请求名称带格式扩展名至mimeType的映射,即 /user.json => application/json -->
  85. <property name="mediaTypes">
  86. <map>
  87. <entry key="json" value="application/json" />
  88. </map>
  89. </property>
  90. <!-- 请求名称中沒有格式扩展名或沒用格式扩展名的mediaTypes時即: "/user/1" 時的默认展示的形式 -->
  91. <property name="defaultContentType" value="text/html" />
  92. <!-- /userinfo/123?format=json 的支持 -->
  93. <property name="favorParameter" value="false" />
  94. <property name="viewResolvers">
  95. <list>
  96. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
  97. <property name="prefix">
  98. <value>/WEB-INF/views/</value>
  99. </property>
  100. <property name="suffix">
  101. <value>.jsp</value>
  102. </property>
  103. </bean>
  104. </list>
  105. </property>
  106. <property name="defaultViews">
  107. <list>
  108. <!-- for application/json -->
  109. <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
  110. <!-- prevent JSON Hijacking -->
  111. <property name="prefixJson" value="false" />
  112. </bean>
  113. </list>
  114. </property>
  115. </bean>
  116. <!-- 开启注解模式 -->
  117. <mvc:annotation-driven/>
  118. </beans>