1.一次加载多个bean xml文件的两种方式
1.在一个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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--定义bean对象-->
<import resource="beans.xml"></import>
<import resource="spring.xml"></import>
</beans>
BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring.xml");
2.直接读取多个xml
BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring.xml","userservice.xml");
2.绝对路径与相对路径的加载差异
1.相对:
ApplicationContext app=new ClassPathXmlApplicationContext("spring.xml");
2.绝对
BeanFactory fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext("从盘符开始的路径");