多IOC容器整合
SSM整合方式
Spring、SpringMVC、MyBatis
SpringMVC的核心Servlet会启动一个IOC容器,而ContextLoaderListener也会启动一个IOC容器。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 在Servlet的上下文参数中指定Spring配置文件的配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-tx.xml</param-value>
</context-param>
<listener>
<!-- 配置ContextLoaderListener监听器,初始化WebApplicationContext这个类型的IOC容器 -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
对象重复创建为问题
两个IOC容器分别扫描不同的包时不会有重复创建对象问题[推荐]
SpringMVC扫描:com.ioc.component.handler
Spring扫描:
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120343709
标签:xml,容器,web,SpringMVC,Spring,MVC,IOC From: https://www.cnblogs.com/wangchuanxinshi/p/16720422.html