spring-total表示主配置文件,包含其他配置文件,一般不定义对象
<import resource="classpath:类路径/xx.xml"/>
除了可以单个指定外,还可以使用通配符统一指定,注意主配置文件不能包含在通配符的范围之内
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"
4 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5 <!--
6 spring-total表示主配置文件,包含其他配置文件,一般不定义对象
7 <import resource="classpath:类路径/xx.xml"/>
8 除了可以单个指定外,还可以使用通配符统一指定,注意主配置文件不能包含在通配符的范围之内
9 -->
10 <!-- <import resource="spring-school.xml"/>
11 <import resource="spring-student.xml"/>-->
12 <import resource="classpath:ba06/spring-*.xml"/>
13
14 </beans>
1 package com.bjpowernode;
2
3 import com.bjpowernode.ba06.Student;
4 import org.junit.Test;
5 import org.springframework.context.ApplicationContext;
6 import org.springframework.context.support.ClassPathXmlApplicationContext;
7
8 public class MyTest06 {
9 @Test
10 public void test05(){
11 /*使用byType的方式实现对象属性的自动注入*/
12 String conf = "ba06/total.xml";
13 ApplicationContext ac = new ClassPathXmlApplicationContext(conf);
14 Student student = (Student) ac.getBean("myStudent");
15 System.out.println(student);
16 }
17 }