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

Spring實戰(zhàn)之搜索Bean類操作示例

 更新時間:2019年12月18日 10:25:12   作者:cakincqm  
這篇文章主要介紹了Spring實戰(zhàn)之搜索Bean類操作,結合實例形式分析了Spring搜索Bean類的相關配置、接口實現(xiàn)與操作技巧,需要的朋友可以參考下

本文實例講述了Spring實戰(zhàn)之搜索Bean類操作。分享給大家供大家參考,具體如下:

一 配置文件

<?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;
  }
  // 實現(xiàn)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)
  {
    // 創(chuàng)建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]

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

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

相關文章

  • 使用@PropertySource讀取配置文件通過@Value進行參數(shù)注入

    使用@PropertySource讀取配置文件通過@Value進行參數(shù)注入

    這篇文章主要介紹了使用@PropertySource讀取配置文件通過@Value進行參數(shù)注入,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • JAVA 注解詳解及簡單實例

    JAVA 注解詳解及簡單實例

    這篇文章主要介紹了JAVA 注解詳解及簡單實例的相關資料,需要的朋友可以參考下
    2017-05-05
  • SQLSyntaxErrorException-ExecutorException報錯解決分析

    SQLSyntaxErrorException-ExecutorException報錯解決分析

    這篇文章主要為大家介紹了SQLSyntaxErrorException-ExecutorException報錯解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-08-08
  • Springboot動態(tài)配置AOP切點詳解

    Springboot動態(tài)配置AOP切點詳解

    這篇文章主要介紹了Springboot動態(tài)配置AOP切點詳解,Springboot 可以定義注解切點去攔截注解修飾的類方法以及execution(xxxx)切點去攔截具體的類方法,默認情況下我們都會使用注解@PointCut去定義切點,然后定義切面攔截切點,需要的朋友可以參考下
    2023-09-09
  • Java GC 機制與內(nèi)存分配策略詳解

    Java GC 機制與內(nèi)存分配策略詳解

    這篇文章主要介紹了Java GC 機制與內(nèi)存分配策略詳解的相關資料,需要的朋友可以參考下
    2017-02-02
  • Java設計模式之迭代模式(Iterator模式)介紹

    Java設計模式之迭代模式(Iterator模式)介紹

    這篇文章主要介紹了Java設計模式之迭代模式(Iterator模式)介紹,本文用一個老師點名的現(xiàn)象描述了迭代模式的使用,需要的朋友可以參考下
    2015-03-03
  • Spring Boot 中實現(xiàn)跨域的多種方式小結

    Spring Boot 中實現(xiàn)跨域的多種方式小結

    Spring Boot提供了多種方式來實現(xiàn)跨域請求,開發(fā)者可以根據(jù)具體需求選擇適合的方法,在配置時,要確保不僅考慮安全性,還要兼顧應用的靈活性和性能,本文給大家介紹Spring Boot 中實現(xiàn)跨域的多種方式,感興趣的朋友一起看看吧
    2024-01-01
  • Java Excel透視表相關操作實現(xiàn)代碼

    Java Excel透視表相關操作實現(xiàn)代碼

    這篇文章主要介紹了Java Excel透視表相關操作實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-08-08
  • 解決springboot3:mybatis-plus依賴錯誤:org.springframework.beans.factory.UnsatisfiedDependencyException

    解決springboot3:mybatis-plus依賴錯誤:org.springframework.beans.fac

    這篇文章主要介紹了解決springboot3:mybatis-plus依賴錯誤:org.springframework.beans.factory.UnsatisfiedDependencyException問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 淺談spring.factories文件的作用

    淺談spring.factories文件的作用

    本文主要介紹了淺談spring.factories文件的作用,spring.factories文件是Spring?Boot自動配置的核心文件之一,它的作用是將各種自動配置類與對應的配置類集中在一起,下面就來介紹一下如何使用,感興趣的可以了解一下
    2024-06-06

最新評論