欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

本文實(shí)例講述了Spring實(shí)戰(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">
   <!-- 自動(dòng)掃描指定包及其子包下的所有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;
  }
  // 實(shí)現(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 "石斧砍柴好慢";
  }
}

四 測(cè)試類

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實(shí)例的名
    System.out.println("--------------" +
      java.util.Arrays.toString(ctx.getBeanDefinitionNames()));
  }
}

五 測(cè)試結(jié)果

--------------[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]

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

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

相關(guān)文章

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

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

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

    JAVA 注解詳解及簡(jiǎn)單實(shí)例

    這篇文章主要介紹了JAVA 注解詳解及簡(jiǎn)單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • SQLSyntaxErrorException-ExecutorException報(bào)錯(cuò)解決分析

    SQLSyntaxErrorException-ExecutorException報(bào)錯(cuò)解決分析

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

    Springboot動(dòng)態(tài)配置AOP切點(diǎn)詳解

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

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

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

    Java設(shè)計(jì)模式之迭代模式(Iterator模式)介紹

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

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

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

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

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

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

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

    淺談spring.factories文件的作用

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

最新評(píng)論