包含关系
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <import resource="classpath:com/gqc/di14/spring-base.xml"/>
<import resource="classpath:com/gqc/di14/spring-beans.xml"/> -->
<import resource="classpath:com/gqc/di14/spring-*.xml"/><!-- 总配置文件不能叫spring-xxx 否则会把自己包含出错 -->
</beans>
平等关系
package com.gqc.di13;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyTest {
@Test
public void test01() {
//创建容器对象 加载Spring 配置文件
/* String resource = "com/gqc/di13/spring-base.xml";
String resource2 = "com/gqc/di13/spring-beans.xml";
ApplicationContext ac=new ClassPathXmlApplicationContext(resource,resource2);*/
/* String resource = "com/gqc/di13/spring-base.xml";
String resource2 = "com/gqc/di13/spring-beans.xml";
String []resources={resource,resource2};
ApplicationContext ac=new ClassPathXmlApplicationContext(resources);*/
String resource = "com/gqc/di13/spring-*.xml";
ApplicationContext ac=new ClassPathXmlApplicationContext(resource);
Student student=(Student) ac.getBean("myStudent");
System.out.println(student);
Teacher teacher=(Teacher)ac.getBean("myTeacher");
System.out.println(teacher);
}
} n