spring-mvc.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.2.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  9. http://www.springframework.org/schema/mvc
  10. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  11. ">
  12. <!-- Spring MVC 扫描目录 -->
  13. <context:component-scan base-package="com.persagy.web.controller">
  14. <!-- 只包括@Controller -->
  15. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  16. </context:component-scan>
  17. <!-- 文件上传解析器 -->
  18. <bean id="multipartResolver"
  19. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  20. <!-- 表示用来解析request请求的默认编码格式,当没有指定的时候根据Servlet规范会使用默认值ISO-8859-1。当request自己指明了它的编码格式的时候就会忽略这里指定的defaultEncoding -->
  21. <property name="defaultEncoding" value="UTF-8" />
  22. <!-- 设置上传文件时的临时目录,默认是Servlet容器的临时目录。 -->
  23. <!--<property name="uploadTempDir" value=""/> -->
  24. <!-- 设置允许上传的最大文件大小,以字节为单位计算。当设为-1时表示无限制,默认是-1。 -->
  25. <property name="maxUploadSize" value="-1" />
  26. <!-- 设置在文件上传时允许写到内存中的最大值,以字节为单位计算,默认是10240。 -->
  27. <!--<property name="maxInMemorySize" value="200000"/> -->
  28. </bean>
  29. <bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  30. <property name="objectMapper" ref="objectMapper"></property>
  31. <property name="supportedMediaTypes">
  32. <list>
  33. <value>application/json;charset=UTF-8</value>
  34. <value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->
  35. </list>
  36. </property>
  37. </bean>
  38. <!-- 二进制数据 -->
  39. <bean id="byteArrayHttpMessageConverter" class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
  40. </bean>
  41. <!-- 文本数据 -->
  42. <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
  43. <!--避免出现乱码 -->
  44. <constructor-arg value="UTF-8" index="0"></constructor-arg>
  45. <property name="supportedMediaTypes">
  46. <list>
  47. <value>text/plain;charset=UTF-8</value>
  48. <value>text/html;charset=UTF-8</value>
  49. </list>
  50. </property>
  51. </bean>
  52. <mvc:annotation-driven>
  53. <mvc:message-converters>
  54. <ref bean="stringHttpMessageConverter" />
  55. <ref bean="byteArrayHttpMessageConverter" />
  56. <ref bean="mappingJackson2HttpMessageConverter" />
  57. </mvc:message-converters>
  58. </mvc:annotation-driven>
  59. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  60. <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
  61. <property name="prefix" value="/WEB-INF/jsp/" />
  62. <property name="suffix" value=".jsp" />
  63. </bean>
  64. </beans>