SpringIOC注入模塊中xml文件導入其他xml文件配置



如果我們在spring框架中配置了多個xml文件,我們可以在讀取配置文件的時候把這些xml文件一下全都讀取
也可以只讀一個總的xml文件,在這個總的xml文件中把其他的xml全都都導入進來。

例如:
student.xml文件:

<bean name="student" class="com.briup.bean.Student">
<property name="id">
<value>25</value>
</property>
</bean>

teacher.xml文件:

<bean name="teacher" class="com.briup.bean.Teacher">
<property name="student" ref="student"></property>
</bean>

import.xml文件:

<import resource="teacher.xml"/>
<import resource="student.xml"/>

main:

String[] path = {"com/briup/ioc/imp/import.xml"};
ApplicationContext container = 
new ClassPathXmlApplicationContext(path);

Teacher t = (Teacher) container.getBean("teacher");
System.out.println(t.getStudent());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM