SpringMVC与Spring整合
SpringMVC只负责Control层,把Spring容器设置为SpringMVC的父容器,子容器可以操作父容器的对象。
即Control层可以完成service层和dao层的调用。
将Spring容器存放在application中(全局),并在tomcat启动时完成初始化。注意:父容器是无法感知子容器的,即父容器无法操作子容器。之后再SpringMVC容器初始化后,将Spring容器设置为父容器。
web.xml中配置监听器
tomcat启动时加载spring
<!-- 配置spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
SpringMVC与Spring整合完成。
项目打包 提取码:6m99
环境:eclipse