99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

如何在Spring中操作Bean類-創新互聯

本篇文章給大家分享的是有關如何在Spring中操作Bean類,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

成都創新互聯公司從2013年創立,先為宣威等服務建站,宣威等地企業,進行企業商務咨詢服務。為宣威企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

一 配置文件

<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.0.xsd">
   <!-- 自動掃描指定包及其子包下的所有Bean類 -->
   <context:component-scan
      base-package="org.crazyit.app.service"/>
</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();
}

三 Bean

Chinese

package org.crazyit.app.service.impl;
import org.springframework.stereotype.*;
import org.crazyit.app.service.*;
@Component
public class Chinese
  implements Person
{
  private Axe axe;
  // axe的setter方法
  public void setAxe(Axe axe)
  {
    this.axe = axe;
  }
  // 實現Person接口的useAxe()方法
  public void useAxe()
  {
    System.out.println(axe.chop());
  }
}

SteelAxe

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

StoneAxe

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

四 測試類

package lee;
import org.springframework.context.*;
import org.springframework.context.support.*;
public class BeanTest
{
  public static void main(String[] args)
  {
    // 創建Spring容器
    ApplicationContext ctx = new
      ClassPathXmlApplicationContext("beans.xml");
    // 獲取Spring容器中的所有Bean實例的名
    System.out.println("--------------" +
      java.util.Arrays.toString(ctx.getBeanDefinitionNames()));
  }
}

五 測試結果

--------------[chinese, steelAxe, stoneAxe,  org.springframework.context.annotation.internalConfigurationAnnotationProcessor,  org.springframework.context.annotation.internalAutowiredAnnotationProcessor,  org.springframework.context.annotation.internalRequiredAnnotationProcessor,  org.springframework.context.annotation.internalCommonAnnotationProcessor,  org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,  org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]

以上就是如何在Spring中操作Bean類,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創新互聯網站建設公司行業資訊頻道。

另外有需要云服務器可以了解下創新互聯建站www.yijiale78.com,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前標題:如何在Spring中操作Bean類-創新互聯
文章地址:http://www.yijiale78.com/article28/cdiecp.html

成都網站建設公司_創新互聯,為您提供標簽優化用戶體驗、服務器托管外貿網站建設Google、域名注冊

廣告

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

網站建設網站維護公司