亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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)文章

  • struts2攔截器_動力節(jié)點Java學院整理

    struts2攔截器_動力節(jié)點Java學院整理

    如何使用struts2攔截器,或者自定義攔截器。下面通過實例代碼給大家分享struts2攔截器的相關(guān)知識,感興趣的朋友參考下吧
    2017-09-09
  • java中l(wèi)ong數(shù)據(jù)類型轉(zhuǎn)換為int類型

    java中l(wèi)ong數(shù)據(jù)類型轉(zhuǎn)換為int類型

    這篇文章主要講解Java中基本數(shù)據(jù)類型,java long 類型與其java int類型的轉(zhuǎn)換的幾種方法,希望能給大家做一個參考
    2016-07-07
  • mybatis plus代碼生成工具的實現(xiàn)代碼

    mybatis plus代碼生成工具的實現(xiàn)代碼

    這篇文章主要介紹了mybatis plus代碼生成工具的實現(xiàn)代碼,需要的朋友可以參考下
    2021-04-04
  • Java 中FastJson的基本使用

    Java 中FastJson的基本使用

    fastjson 是一個性能很好的 Java 語言實現(xiàn)的 JSON 解析器和生成器,來自阿里巴巴的工程師開發(fā)。下面通過本文給大家介紹Java 中FastJson的基本使用,需要的朋友參考下吧
    2017-11-11
  • 最新評論