spring中怎么實(shí)現(xiàn)兩個xml配置文件間的互調(diào)

這篇文章將為大家詳細(xì)講解有關(guān)spring中怎么實(shí)現(xiàn)兩個xml配置文件間的互調(diào),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)主營普陀網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),普陀h5微信小程序定制開發(fā)搭建,普陀網(wǎng)站營銷推廣歡迎普陀等地區(qū)企業(yè)咨詢

首先建兩個測試類

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();  }}

關(guān)于spring中怎么實(shí)現(xiàn)兩個xml配置文件間的互調(diào)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文題目:spring中怎么實(shí)現(xiàn)兩個xml配置文件間的互調(diào)
URL網(wǎng)址:http://muchs.cn/article6/jejgog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄Google、網(wǎng)頁設(shè)計公司全網(wǎng)營銷推廣、App設(shè)計用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司