1.4 import引入其他配置文件

戴着假发的程序员 出品

[查看视频讲解]

我们可以通过import在一个配置文件中引入其他的配置文件。 例如:

<?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="applicationContext-service.xml"/>
    <import resource="applicationContext-dao.xml"/>
    <bean id="accountDAO_1" class="com.boxuewa.dk.demo1.dao.AccountDAO"/>
</beans>

这时我们就可以这样创建容器了:

ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

 

posted @ 2020-10-02 21:41  戴着假发的程序员0-1  阅读(185)  评论(0编辑  收藏  举报