Spring中的父子容器
父子容器的特点是:
子容器中可以访问父容器中的Bean,但父容器中访问不到子容器中的Bean
1. Spring容器的创建
在tomcat中创建spring容器的方式有两种,
- 一种是通过DispatcherServlet配置web.xml进行生成,
- 另一种是通过ContextPathListener监听器进行配置
2.两个Spring容器的关联方式
这里两个容器获取与创建方式没有关系,两种创建方式都可以
spring-parent.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="p1" class="java.lang.String" c:original="parent"></bean>
</beans>
spring-child.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springfra