spring-mvc.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
  7. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
  9. <!-- ①:对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
  10. <context:component-scan base-package="cn.ourwill" use-default-filters="false">
  11. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  12. <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
  13. <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
  14. <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
  15. </context:component-scan>
  16. <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
  17. <mvc:message-converters register-defaults="true">
  18. <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
  19. <bean class="org.springframework.http.converter.StringHttpMessageConverter">
  20. <constructor-arg value="UTF-8" />
  21. </bean>
  22. <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true -->
  23. <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  24. <property name="prettyPrint" value="true"/>
  25. </bean>
  26. </mvc:message-converters>
  27. </mvc:annotation-driven>
  28. <!-- <mvc:resources mapping="/static/**" location="/static/"/> -->
  29. <mvc:default-servlet-handler />
  30. <!-- ②:拦截器的配置
  31. <mvc:interceptors>
  32. <mvc:interceptor>
  33. <mvc:mapping path="/**/*"/>
  34. <mvc:exclude-mapping path="/static/**/*"/>
  35. <mvc:exclude-mapping path="/kindeditor/**/*"/>
  36. <bean class="cn.ourwill.core.intercepter.LimitIntercepterForWebsite">
  37. </bean>
  38. </mvc:interceptor>
  39. 针对后台的路径进行拦截
  40. <mvc:interceptor>
  41. <mvc:mapping path="/admin*"/>
  42. <mvc:mapping path="/admin/**/*"/>
  43. <mvc:exclude-mapping path="/*/ajax/**"/>
  44. <mvc:exclude-mapping path="/api/*"/>
  45. <mvc:exclude-mapping path="/api/**/*"/>
  46. <mvc:exclude-mapping path="/admin"/>
  47. <mvc:exclude-mapping path="/admin"/>
  48. <mvc:exclude-mapping path="/admin/sys/login"/>
  49. <mvc:exclude-mapping path="/admin/sys/logout"/>
  50. <bean class="cn.ourwill.core.intercepter.LimitIntercepterForAdmin">
  51. </bean>
  52. </mvc:interceptor>
  53. 访问日志
  54. <mvc:interceptor>
  55. <mvc:mapping path="/**/*"/>
  56. <mvc:exclude-mapping path="/static/**/*"/>
  57. <mvc:exclude-mapping path="/kindeditor/**/*"/>
  58. <bean class="cn.ourwill.core.intercepter.LoggerFilter">
  59. </bean>
  60. </mvc:interceptor>
  61. </mvc:interceptors> -->
  62. <!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 -->
  63. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  64. <property name="prefix" value="/WEB-INF/view/"/>
  65. <property name="suffix" value=".jsp"/>
  66. <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  67. </bean>
  68. <!-- <mvc:view-controller path="/" view-name="redirect:/index"/> -->
  69. <!-- REST中根据URL后缀自动判定Content-Type及相应的View -->
  70. <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
  71. <property name="mediaTypes" >
  72. <value>
  73. json=application/json
  74. xml=application/xml
  75. </value>
  76. </property>
  77. </bean>
  78. <!-- 文件上传限制大小 -->
  79. <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  80. <!-- set the max upload size 10MB -->
  81. <property name="maxUploadSize">
  82. <value>10485760</value>
  83. </property>
  84. <property name="maxInMemorySize">
  85. <value>4096</value>
  86. </property>
  87. </bean>
  88. <!-- 将Controller抛出的异常转到特定View, 保持SiteMesh的装饰效果 -->
  89. <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  90. <property name="exceptionMappings">
  91. <props>
  92. <prop key="org.apache.shiro.authz.UnauthorizedException">/WEB-INF/view/common/error/403</prop>
  93. <prop key="java.lang.Throwable">/common/error</prop>
  94. </props>
  95. </property>
  96. </bean>
  97. <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  98. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  99. <property name="basePackage" value="cn.ourwill"/>
  100. </bean>
  101. </beans>