SpringMvc.xml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  6. xmlns:mvc="http://www.springframework.org/schema/mvc"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  9. http://www.springframework.org/schema/mvc
  10. http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  11. http://code.alibabatech.com/schema/dubbo
  12. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  13. http://www.springframework.org/schema/context
  14. http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  15. <!--加载静态资源-->
  16. <mvc:default-servlet-handler/>
  17. <!--配置@Controller注解扫描-->
  18. <context:component-scan base-package="com.persagy.controller"></context:component-scan>
  19. <!--注解驱动:
  20. 自动配置最新版的注解的处理器映射器和处理器适配器-->
  21. <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
  22. <!--配置视图解析器:
  23. 作用:在Controller中指定页面路径的时候就不用写页面的完整路径名和扩展名称了-->
  24. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  25. <!--真正的jsp访问路径是前缀+Controller里的 modelAndView.setViewName()的页面名称+后缀-->
  26. <!--前缀-->
  27. <property name="prefix" value="/WEB-INF/jsp/"></property>
  28. <!--后缀-->
  29. <property name="suffix" value=".jsp"></property>
  30. </bean>
  31. <!-- 配置自定义转换器
  32. 注意: 一定要将自定义的转换器配置到注解驱动上
  33. -->
  34. <bean id="conversionService"
  35. class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
  36. <property name="converters">
  37. <set>
  38. <!-- 指定自定义转换器的全路径名称 -->
  39. <bean class="com.persagy.controller.converter.StringToDateConverter"/>
  40. </set>
  41. </property>
  42. </bean>
  43. <bean id="utf8Charset" class="java.nio.charset.Charset"
  44. factory-method="forName">
  45. <constructor-arg value="UTF-8"/>
  46. </bean>
  47. <mvc:annotation-driven>
  48. <mvc:message-converters>
  49. <bean class="org.springframework.http.converter.StringHttpMessageConverter">
  50. <constructor-arg ref="utf8Charset"/>
  51. </bean>
  52. </mvc:message-converters>
  53. </mvc:annotation-driven>
  54. </beans>