[关闭]
@chenbinghua 2019-03-02T07:44:05.000000Z 字数 2179 阅读 635

# 小码哥java第二项目--CRM项目(二)

java


spring和springmvc整合

web.xml配置springmvc的前端控制器DispatcherServlet
在服务器启动的事件就创建DispatcherServlet
然后根据配置文件创建spring容器和springmvc相关程序

  1. <servlet>
  2. <servlet-name>springmvc</servlet-name>
  3. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  4. <init-param>
  5. <param-name>contextConfigLocation</param-name>
  6. <param-value>classpath:applicationContext-mvc.xml</param-value>
  7. </init-param>
  8. <load-on-startup>1</load-on-startup>
  9. </servlet>
  10. <servlet-mapping>
  11. <servlet-name>springmvc</servlet-name>
  12. <url-pattern>/</url-pattern>
  13. </servlet-mapping>

springmvc指定的配置文件

  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:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xmlns:mvc="http://www.springframework.org/schema/mvc"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  10. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  11. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  13. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  14. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
  15. <!--0.扫描所有的注解-->
  16. <context:component-scan base-package="com._520it.crm"/>
  17. <!--1.配置注解的驱动支持-->
  18. <mvc:annotation-driven/>
  19. <!--2.配置静态资源的处理器-->
  20. <mvc:default-servlet-handler/>
  21. <!--3.配置视图解析器-->
  22. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  23. <property name="prefix" value="/WEB-INF/views/"/>
  24. <property name="suffix" value=".jsp"/>
  25. </bean>
  26. <!--4.引入配置文件-->
  27. <import resource="classpath:applicationContext.xml"/>
  28. </beans>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注