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

Spring實戰(zhàn)之抽象Bean和子Bean定義與用法示例

 更新時間:2019年11月22日 11:54:45   作者:cakincqm  
這篇文章主要介紹了Spring實戰(zhàn)之抽象Bean和子Bean定義與用法,結(jié)合實例形式分析了Spring抽象Bean和子Bean相關(guān)配置、定義與使用操作技巧,需要的朋友可以參考下

本文實例講述了Spring實戰(zhàn)之抽象Bean和子Bean定義與用法。分享給大家供大家參考,具體如下:

一 配置

<?xml version="1.0" encoding="GBK"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://www.springframework.org/schema/beans"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
   <!-- 定義Axe實例 -->
   <bean id="steelAxe" class="org.crazyit.app.service.impl.SteelAxe"/>
   <!-- 指定abstract="true"定義抽象Bean -->
   <bean id="personTemplate" abstract="true">
      <property name="name" value="crazyit"/>
      <property name="axe" ref="steelAxe"/>
   </bean>
   <!-- 通過指定parent屬性指定下面Bean配置可從父Bean繼承得到配置信息 -->
   <bean id="chinese" class="org.crazyit.app.service.impl.Chinese"
      parent="personTemplate"/>
   <bean id="american" class="org.crazyit.app.service.impl.American"
      parent="personTemplate"/>
</beans>

二 接口

Axe

package org.crazyit.app.service;
public interface Axe
{
   public String chop();
}

Person

package org.crazyit.app.service;
public interface Person
{
   public void useAxe();
}

三 實現(xiàn)類

1 American

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class American implements Person
{
   private Axe axe;
   private String name;
   public void setAxe(Axe axe)
   {
      System.out.println("Spring執(zhí)行依賴關(guān)系注入...");
      this.axe = axe;
   }
   public void setName(String name)
   {
      this.name = name;
   }
   public void useAxe()
   {
      System.out.println("我是美國人:名字為:" + name
        + "。正在用斧頭" + axe.chop());
   }
}

2 Chinese

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class Chinese implements Person
{
   private Axe axe;
   private String name;
   public void setAxe(Axe axe)
   {
      System.out.println("Spring執(zhí)行依賴關(guān)系注入...");
      this.axe = axe;
   }
   public void setName(String name)
   {
      this.name = name;
   }
   public void useAxe()
   {
      System.out.println("我是中國人:名字為:" + name
        + "。正在用斧頭" + axe.chop());
   }
}

3 SteelAxe

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class SteelAxe implements Axe
{
   public String chop()
   {
      return "鋼斧砍柴真快";
   }
}

4 StoneAxe

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class StoneAxe implements Axe
{
   public String chop()
   {
      return "石斧砍柴好慢";
   }
}

四 測試類

package lee;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.*;
import org.crazyit.app.service.*;
public class BeanTest
{
  public static void main(String[] args)
  {
    ApplicationContext ctx = new
      ClassPathXmlApplicationContext("beans.xml");
  }
}

五 測試結(jié)果

Spring執(zhí)行依賴關(guān)系注入...
Spring執(zhí)行依賴關(guān)系注入...

更多關(guān)于java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Spring框架入門與進階教程》、《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Java操作DOM節(jié)點技巧總結(jié)》、《Java文件與目錄操作技巧匯總》和《Java緩存操作技巧匯總

希望本文所述對大家java程序設(shè)計有所幫助。

相關(guān)文章

  • SpringBoot測試之高級配置方式

    SpringBoot測試之高級配置方式

    這篇文章主要介紹了SpringBoot測試之高級配置方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • 基于java+springboot+mybatis+laiyu實現(xiàn)學(xué)科競賽管理系統(tǒng)

    基于java+springboot+mybatis+laiyu實現(xiàn)學(xué)科競賽管理系統(tǒng)

    這篇文章主要介紹了基于java+springboot+mybatis+laiyu實現(xiàn)的學(xué)科競賽管理系統(tǒng),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • Java IO讀取文件的實例詳解

    Java IO讀取文件的實例詳解

    這篇文章主要介紹了Java IO讀取文件的實例詳解的相關(guān)資料,主要介紹字符流和字節(jié)流的內(nèi)容,需要的朋友可以參考下
    2017-07-07
  • SpringMVC4+MyBatis+SQL Server2014實現(xiàn)數(shù)據(jù)庫讀寫分離

    SpringMVC4+MyBatis+SQL Server2014實現(xiàn)數(shù)據(jù)庫讀寫分離

    這篇文章主要介紹了SpringMVC4+MyBatis+SQL Server2014實現(xiàn)讀寫分離,需要的朋友可以參考下
    2017-04-04
  • SpringBoot Actuator埋點和監(jiān)控及簡單使用

    SpringBoot Actuator埋點和監(jiān)控及簡單使用

    最近做的項目涉及到埋點監(jiān)控、報表、日志分析的相關(guān)知識,于是搗鼓的一番,下面把涉及的知識點及SpringBoot Actuator埋點和監(jiān)控的簡單用法,給大家分享下,感興趣的朋友一起看看吧
    2021-11-11
  • Java Grpc實例創(chuàng)建負載均衡詳解

    Java Grpc實例創(chuàng)建負載均衡詳解

    這篇文章主要介紹了Java Grpc實例創(chuàng)建負載均衡詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-03-03
  • Java反射機制(Reflection)淺析

    Java反射機制(Reflection)淺析

    這篇文章主要介紹了Java反射機制(Reflection)淺析,本文以實例講解Java的反射機制,需要的朋友可以參考下
    2014-07-07
  • 詳解Spring容器的使用流程

    詳解Spring容器的使用流程

    今天給大家?guī)淼氖顷P(guān)于Java的相關(guān)知識,文章圍繞著Spring容器的使用流程展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • springboot~ObjectMapper~dto到entity的自動賦值

    springboot~ObjectMapper~dto到entity的自動賦值

    這篇文章主要介紹了springboot~ObjectMapper~dto到entity的自動賦值,本文分三種情況給大家介紹,需要的朋友可以參考下
    2018-08-08
  • idea同時打開多個項目的圖文教程

    idea同時打開多個項目的圖文教程

    這篇文章主要給大家介紹了idea同時打開多個項目的圖文教程,文章通過圖文結(jié)合的形式給大家講解的非常詳細,對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-02-02

最新評論