欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

spring中怎么利用xml裝配bean

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)spring中怎么利用xml裝配bean,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創(chuàng)新互聯(lián)主營(yíng)蕪湖縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都APP應(yīng)用開(kāi)發(fā),蕪湖縣h5成都微信小程序搭建,蕪湖縣網(wǎng)站營(yíng)銷推廣歡迎蕪湖縣等地區(qū)企業(yè)咨詢

使用XML裝配bean,在bean中調(diào)用另一個(gè)bean方法,首先建一個(gè)Dog類和一個(gè)Cat類

package soundsystem;public class Dog {private String Cry;//叫聲//用setter方法注入public void setCry(String cry) {  Cry = cry;}//定義一個(gè)狗叫方法  public void DogCry(){    System.out.println("狗叫:"+Cry);    Cat.CatCry();    catEat.CatEating();  }}

package soundsystem;public class Cat {  private String Cry;//叫聲//用構(gòu)造函數(shù)注入  public Cat(String cry){    this.Cry=cry;  }//定義一個(gè)貓叫方法  public void CatCry(){    System.out.println("貓叫:"+Cry);  }}

一個(gè)配置類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">  <bean id="Dog" class="soundsystem.Dog">    <property name="Cry" value="汪汪汪~(yú)"></property>    <property name="Cat" ref="Cat"></property>  </bean>  <bean id="Cat" class="soundsystem.Cat">    <constructor-arg value="喵~"></constructor-arg>  </bean></beans>

現(xiàn)在開(kāi)始測(cè)試

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

上述就是小編為大家分享的spring中怎么利用xml裝配bean了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:spring中怎么利用xml裝配bean
URL分享:http://chinadenli.net/article12/gehsdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)網(wǎng)站設(shè)計(jì)企業(yè)建站網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)公司微信公眾號(hào)

廣告

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

成都seo排名網(wǎng)站優(yōu)化