使用场景:
<bean id="hello" class="indi.jaywee.pojo.HelloSpring">
<constructor-arg name="id" value="7"/>
<constructor-arg name="name" value="jaywee"/>
</bean>
<alias name="hello" alias="hello1"/>
<!-- 还可以为别名起别名,相当于多个别名 -->
<alias name="hello1" alias="hello2"/>
<bean id="hello" class="indi.jaywee.pojo.HelloSpring" name="hello3 hello4,hello5;hello6">
<constructor-arg name="id" value="7"/>
<constructor-arg name="name" value="jaywee"/>
</bean>
常用配置:
用于协同开发, 可以将多个配置文件,导入合并为一个。
在实例化容器时,可以传入多个参数。
// 实例化容器
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml", "beans1.xml", "beans2.xml");
通过import标签,将多个配置文件合并成为一个总的配置文件(applicationContext.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
https://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="beans.xml"/>
<import resource="beans1.xml"/>
<import resource="beans2.xml"/>
</beans>
在实例化容器时,只需要传入applicationContext.xml
即可
// 实例化容器
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
原文:https://www.cnblogs.com/secretmrj/p/15082788.html