spring-mvc.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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" xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:cache="http://www.springframework.org/schema/cache"
  7. xmlns:p="http://www.springframework.org/schema/p"
  8. xmlns:task="http://www.springframework.org/schema/task"
  9. xsi:schemaLocation="http://www.springframework.org/schema/beans
  10. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  11. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  13. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  14. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  15. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  16. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
  17. <!-- 扫描包,默认扫描所有 com.tqe下的所有注解 -->
  18. <context:component-scan base-package="com.tqe"/>
  19. <aop:aspectj-autoproxy />
  20. <!-- mvc注解驱动 -->
  21. <mvc:annotation-driven conversion-service="conversionService" >
  22. <mvc:argument-resolvers>
  23. <bean class="com.tqe.base.web.resolver.PageVOHandlerMethodArgumentResolver" />
  24. </mvc:argument-resolvers>
  25. </mvc:annotation-driven>
  26. <!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
  27. <cache:annotation-driven cache-manager="cacheManager" />
  28. <bean
  29. class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
  30. <!-- spring mvc请求映射 -->
  31. <bean
  32. class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  33. <property name="synchronizeOnSession" value="true"/>
  34. </bean>
  35. <bean id="conversionService"
  36. class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
  37. <property name="converters">
  38. <set>
  39. <bean class="com.tqe.base.converter.StringConverter"/>
  40. </set>
  41. </property>
  42. </bean>
  43. <!-- 视图解释类 -->
  44. <bean
  45. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  46. <!-- //Controler 返回的ModeAndView自动到此目录下找对应jsp为后缀的文件 -->
  47. <property name="prefix" value="/WEB-INF/jsp/" />
  48. <property name="suffix" value=".jsp" /><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
  49. <!-- 使用Jsp作为视图解释层 -->
  50. <property name="viewClass"
  51. value="org.springframework.web.servlet.view.JstlView" />
  52. </bean>
  53. <!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理 -->
  54. <mvc:resources mapping="/image/**" location="/image/" />
  55. <mvc:resources mapping="/css/**" location="/css/" />
  56. <mvc:resources mapping="/js/**" location="/js/" />
  57. <mvc:resources mapping="/fonts/**" location="/fonts/" />
  58. <!-- 文件上传 -->
  59. <bean id="multipartResolver"
  60. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  61. <property name="defaultEncoding" value="utf-8"/>
  62. <property name="maxInMemorySize" value="40960"/>
  63. <!-- 最大上传20M文件 -->
  64. <property name="maxUploadSize" value="20971520"/>
  65. </bean>
  66. <!-- 导入mybatis的配置信息 -->
  67. <import resource="spring-mybatis.xml" />
  68. <!-- 配置拦截器 -->
  69. <mvc:interceptors>
  70. <mvc:interceptor>
  71. <mvc:mapping path="/admin/stuEval*" />
  72. <bean class="com.tqe.interceptor.StuEvalInterceptor"/>
  73. </mvc:interceptor>
  74. <mvc:interceptor>
  75. <mvc:mapping path="/admin/teaEval*" />
  76. <bean class="com.tqe.interceptor.TeaEvalInterceptor"/>
  77. </mvc:interceptor>
  78. </mvc:interceptors>
  79. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
  80. <property name="messageConverters">
  81. <list>
  82. <bean class = "org.springframework.http.converter.StringHttpMessageConverter">
  83. <property name = "supportedMediaTypes">
  84. <list>
  85. <value>text/plain;charset=UTF-8</value>
  86. </list>
  87. </property>
  88. </bean>
  89. </list>
  90. </property>
  91. </bean>
  92. <!-- 配置responseBody 结果返回json数据 -->
  93. <bean id="jsonConverter"
  94. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
  95. </bean>
  96. <!-- spring自己的换管理器,这里定义了两个缓存位置名称 ,既注解中的value -->
  97. <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
  98. <property name="caches">
  99. <set>
  100. <bean
  101. class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
  102. p:name="mCache" />
  103. </set>
  104. </property>
  105. </bean>
  106. <!-- 全局异常处理 -->
  107. <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  108. <!-- 定义默认的异常处理页面,当该异常类型的注册时使用 -->
  109. <property name="defaultErrorView" value="error"/>
  110. <!-- 定义异常处理页面用来获取异常信息的变量名,默认名为exception -->
  111. <property name="exceptionAttribute" value="ex"/>
  112. <!-- 定义需要特殊处理的异常,用类名或完全路径名作为key,异常也页名作为值 -->
  113. <property name="exceptionMappings">
  114. <props>
  115. <prop key="com.tqe.base.exception.UserNotExistException">error</prop>
  116. <!-- 这里还可以继续扩展对不同异常类型的处理 -->
  117. </props>
  118. </property>
  119. </bean>
  120. <!-- Spring Task 定时任务 -->
  121. <task:annotation-driven scheduler="springScheduler" mode="proxy"/>
  122. <task:scheduler id="springScheduler" pool-size="10"/>
  123. </beans>