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

spring中怎么利用xml裝配bean-創(chuàng)新互聯(lián)

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

成都創(chuàng)新互聯(lián)公司專業(yè)成都做網(wǎng)站、網(wǎng)站設計,集網(wǎng)站策劃、網(wǎng)站設計、網(wǎng)站制作于一體,網(wǎng)站seo、網(wǎng)站優(yōu)化、網(wǎng)站營銷、軟文發(fā)稿等專業(yè)人才根據(jù)搜索規(guī)律編程設計,讓網(wǎng)站在運行后,在搜索中有好的表現(xiàn),專業(yè)設計制作為您帶來效益的網(wǎng)站!讓網(wǎng)站建設為您創(chuàng)造效益。

使用XML裝配bean,在bean中調用另一個bean方法,首先建一個Dog類和一個Cat類

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

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

一個配置類Bean_DogXML.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="/tupian/20230522/"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="/tupian/20230522/ /tupian/20230522//spring-beans.xsd">  <bean id="Dog" class="soundsystem.Dog">    <property name="Cry" value="汪汪汪~"></property>    <property name="Cat" ref="Cat"></property>  </bean>  <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();  }}

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

網(wǎng)頁標題:spring中怎么利用xml裝配bean-創(chuàng)新互聯(lián)
分享鏈接:http://www.chinadenli.net/article46/djdshg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設計公司網(wǎng)頁設計公司電子商務網(wǎng)站改版App設計微信公眾號

廣告

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

成都定制網(wǎng)站建設