[关闭]
@Pollux 2016-07-23T03:21:34.000000Z 字数 2801 阅读 732

再整合spring mvc

web


  1. <!DOCTYPE web-app PUBLIC
  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
  4. <web-app>
  5. <context-param>
  6. <param-name>contextConfigLocation</param-name>
  7. <param-value>classpath:/spring/spring.xml,classpath:/spring/spring-mybatis.xml</param-value>
  8. </context-param>
  9. <listener>
  10. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  11. </listener>
  12. <servlet>
  13. <servlet-name>springDispatcherServlet</servlet-name>
  14. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  15. <init-param>
  16. <param-name>contextConfigLocation</param-name>
  17. <param-value>classpath:spring/spring-mvc.xml</param-value>
  18. </init-param>
  19. <load-on-startup>1</load-on-startup>
  20. </servlet>
  21. <servlet-mapping>
  22. <servlet-name>springDispatcherServlet</servlet-name>
  23. <url-pattern>/</url-pattern>
  24. </servlet-mapping>
  25. <servlet-mapping>
  26. <servlet-name>default</servlet-name>
  27. <url-pattern>*.html</url-pattern>
  28. </servlet-mapping>
  29. </web-app>

最重要的是设置监听器,从而在spring mvc启动时加载spring.xml和spring-mybatis.xml配置文件

  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:context="http://www.springframework.org/schema/context"
  4. xmlns:mvc="http://www.springframework.org/schema/mvc"
  5. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
  8. <context:component-scan base-package="com.pollux.controller"></context:component-scan>
  9. <bean
  10. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  11. <property name="prefix" value="/"></property>
  12. <property name="suffix" value=".jsp"></property>
  13. </bean>
  14. <bean id="multipartResolver"
  15. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  16. <property name="defaultEncoding" value="utf-8"></property>
  17. <property name="maxUploadSize" value="1024000000"></property>
  18. <property name="uploadTempDir" value="/upload"></property>
  19. </bean>
  20. <mvc:annotation-driven>
  21. <mvc:message-converters>
  22. <bean class="org.springframework.http.converter.StringHttpMessageConverter">
  23. <property name="supportedMediaTypes">
  24. <list>
  25. <value>text/plain;charset=UTF-8</value>
  26. <value>text/html;charset=UTF-8</value>
  27. </list>
  28. </property>
  29. </bean>
  30. </mvc:message-converters>
  31. </mvc:annotation-driven>
  32. <mvc:resources location="/upload/" mapping="/upload/**"></mvc:resources>
  33. <mvc:default-servlet-handler/>
  34. </beans>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注