spring如何實現(xiàn)兩個xml配置文件間的互調(diào)
更新時間:2019年11月28日 09:57:05 作者:綠色的草
這篇文章主要介紹了spring如何實現(xiàn)兩個xml配置文件間的互調(diào),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
這篇文章主要介紹了spring如何實現(xiàn)兩個xml配置文件間的互調(diào),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
首先建兩個測試類
package soundsystem; public class Dog { private String Cry; private Cat Cat; public void setCry(String cry) { Cry = cry; } public void setCat(soundsystem.Cat cat) { Cat = cat; } public void DogCry(){ System.out.println("狗叫:"+Cry); Cat.CatCry(); } }
package soundsystem; public class Cat { private String Cry; public Cat(String cry){ this.Cry=cry; } public void CatCry(){ System.out.println("貓叫:"+Cry); } }
然后針對兩類建兩個xml配置文件
Bean_DogXML.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"> <import resource="Bean_CatXML.xml"></import> <bean id="Dog" class="soundsystem.Dog"> <property name="Cry" value="汪汪汪~"></property> <property name="cat" ref="Cat"></property> </bean> </beans>
Bean_CatXML.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 id="Cat" class="soundsystem.Cat"> <constructor-arg value="喵喵~"></constructor-arg> </bean> </beans>
現(xiàn)在開始測試:
package Test; import org.junit.runner.RunWith; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import soundsystem.Cat; import soundsystem.Dog; @RunWith(SpringJUnit4ClassRunner.class) public class Test { @org.junit.Test public static void main(String[] args) { ApplicationContext ap=new ClassPathXmlApplicationContext("config/Bean_DogXML.xml"); Dog dog=(Dog)ap.getBean("Dog"); dog.DogCry(); } }
輸出結(jié)果是:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
MyBatis分頁查詢返回list的時候出現(xiàn)null的問題
這篇文章主要介紹了MyBatis分頁查詢返回list的時候出現(xiàn)null的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07

java中l(wèi)ong數(shù)據(jù)類型轉(zhuǎn)換為int類型
這篇文章主要講解Java中基本數(shù)據(jù)類型,java long 類型與其java int類型的轉(zhuǎn)換的幾種方法,希望能給大家做一個參考
2016-07-07