最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring實(shí)戰(zhàn)之容器后處理器操作示例

 更新時(shí)間:2019年12月17日 09:26:41   作者:cakincqm  
這篇文章主要介紹了Spring實(shí)戰(zhàn)之容器后處理器操作,結(jié)合實(shí)例形式分析了spring容器后處理器配置、使用操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Spring實(shí)戰(zhàn)之容器后處理器。分享給大家供大家參考,具體如下:

一 配置文件

<?xml version="1.0" encoding="GBK"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:p="http://www.springframework.org/schema/p"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
   <!-- 配置兩個(gè)簡單Bean實(shí)例 -->
   <bean id="steelAxe" class="org.crazyit.app.service.impl.SteelAxe"/>
   <bean id="chinese" class="org.crazyit.app.service.impl.Chinese"
      init-method="init" p:name="孫悟空" p:axe-ref="steelAxe"/>
   <!-- 配置容器后處理器 -->
   <bean id="beanFactoryPostProcessor"
      class="org.crazyit.app.util.MyBeanFactoryPostProcessor"/>
</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.beans.factory.InitializingBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.crazyit.app.service.*;
public class Chinese
  implements Person,InitializingBean
{
  private Axe axe;
  private String name;
  public Chinese()
  {
    System.out.println("Spring實(shí)例化主調(diào)bean:Chinese實(shí)例...");
  }
  public void setAxe(Axe axe)
  {
    this.axe = axe;
  }
  public void setName(String name)
  {
    System.out.println("Spring執(zhí)行setName()方法注入依賴關(guān)系...");
    this.name = name;
  }
  public void useAxe()
  {
    System.out.println(name + axe.chop());
  }
  // 下面是兩個(gè)生命周期方法
  public void init()
  {
    System.out.println("正在執(zhí)行初始化方法 init...");
  }
  public void afterPropertiesSet() throws Exception
  {
    System.out.println("正在執(zhí)行初始化方法 afterPropertiesSet...");
  }
}

SteelAxe

package org.crazyit.app.service.impl;
import org.crazyit.app.service.*;
public class SteelAxe
   implements Axe
{
   public SteelAxe()
   {
      System.out.println("Spring實(shí)例化依賴bean:SteelAxe實(shí)例...");
   }
   public String chop()
   {
      return "鋼斧砍柴真快";
   }
}

四 容器后處理器

package org.crazyit.app.util;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
public class MyBeanFactoryPostProcessor
  implements BeanFactoryPostProcessor
{
  /**
   * 重寫該方法,對(duì)Spring進(jìn)行后處理。
   * @param beanFactory Spring容器本身
   */
  public void postProcessBeanFactory(
    ConfigurableListableBeanFactory beanFactory)
    throws BeansException
  {
    System.out.println("程序?qū)pring所做的BeanFactory的初始化沒有改變...");
    System.out.println("Spring容器是:" + beanFactory);
  }
}

五 測(cè)試類

package lee;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.crazyit.app.service.*;
public class BeanTest
{
  public static void main(String[] args)
  {
    // 以ApplicationContex作為Spring容器
    // 它會(huì)自動(dòng)注冊(cè)容器后處理器、Bean后處理器
    ApplicationContext ctx = new
      ClassPathXmlApplicationContext("beans.xml");
    Person p = (Person)ctx.getBean("chinese");
    p.useAxe();
  }
}

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

程序?qū)pring所做的BeanFactory的初始化沒有改變...
Spring容器是:org.springframework.beans.factory.support.DefaultListableBeanFactory@6a024a67: defining beans  [steelAxe,chinese,beanFactoryPostProcessor]; root of factory  hierarchy
Spring實(shí)例化依賴bean:SteelAxe實(shí)例...
Spring實(shí)例化主調(diào)bean:Chinese實(shí)例...
Spring執(zhí)行setName()方法注入依賴關(guān)系...
正在執(zhí)行初始化方法  afterPropertiesSet...
正在執(zhí)行初始化方法   init...
孫悟空鋼斧砍柴真快

更多關(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)文章

  • 基于IO版的用戶登錄注冊(cè)實(shí)例(Java)

    基于IO版的用戶登錄注冊(cè)實(shí)例(Java)

    下面小編就為大家?guī)硪黄贗O版的用戶登錄注冊(cè)實(shí)例(Java)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • scala 隱式轉(zhuǎn)換與隱式參數(shù)的使用方法

    scala 隱式轉(zhuǎn)換與隱式參數(shù)的使用方法

    這篇文章主要介紹了scala 隱式轉(zhuǎn)換與隱式參數(shù)的使用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Java多線程之scheduledThreadPool的方法解析

    Java多線程之scheduledThreadPool的方法解析

    這篇文章主要介紹了Java多線程之scheduledThreadPool的方法解析,queue是DelayedWorkQueue,但通過后面的分析可以知道,最大線程數(shù)是不起作用的,最多會(huì)起核心線程數(shù)的數(shù)量,需要的朋友可以參考下
    2023-12-12
  • 淺談Java中spring 線程異步執(zhí)行

    淺談Java中spring 線程異步執(zhí)行

    這篇文章主要介紹了淺談spring 線程異步執(zhí)行,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Java基礎(chǔ)之List內(nèi)元素的排序性能對(duì)比

    Java基礎(chǔ)之List內(nèi)元素的排序性能對(duì)比

    這篇文章主要介紹了Java基礎(chǔ)之List內(nèi)元素的排序性能對(duì)比,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04
  • Java注解(annotation)簡述

    Java注解(annotation)簡述

    這篇文章主要介紹了使用java的注解(用在java類的方法上的注解)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-08-08
  • 使用FormData上傳二進(jìn)制文件、對(duì)象、對(duì)象數(shù)組方式

    使用FormData上傳二進(jìn)制文件、對(duì)象、對(duì)象數(shù)組方式

    這篇文章主要介紹了使用FormData上傳二進(jìn)制文件、對(duì)象、對(duì)象數(shù)組方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 詳解java中的阻塞隊(duì)列

    詳解java中的阻塞隊(duì)列

    這篇文章主要介紹了java中的阻塞隊(duì)列的相關(guān)知識(shí),文中代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • MyBatis中#和$的區(qū)別小結(jié)

    MyBatis中#和$的區(qū)別小結(jié)

    ${} 和 #{} 都是 MyBatis 中用來替換參數(shù)的,它們都可以將用戶傳遞過來的參數(shù),替換到 MyBatis 最終生成的 SQL 中,但它們區(qū)別卻是很大的,接下來我們一起來看
    2023-09-09
  • SpringBoot實(shí)現(xiàn)MapperScan添加動(dòng)態(tài)配置(占位符)

    SpringBoot實(shí)現(xiàn)MapperScan添加動(dòng)態(tài)配置(占位符)

    這篇文章主要介紹了SpringBoot實(shí)現(xiàn)MapperScan添加動(dòng)態(tài)配置(占位符),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
    2022-01-01

最新評(píng)論

嘉荫县| 南皮县| 河东区| 油尖旺区| 丹巴县| 玛曲县| 泰兴市| 巴中市| 贡嘎县| 景泰县| 蛟河市| 缙云县| 邵阳市| 皮山县| 永和县| 和田县| 尉氏县| 霞浦县| 英吉沙县| 侯马市| 松潘县| 山西省| 临澧县| 屏南县| 丹寨县| 来凤县| 高邮市| 股票| 牟定县| 万山特区| 肇州县| 远安县| 辽阳市| 沂源县| 临城县| 济南市| 琼海市| 莲花县| 屏东县| 阳春市| 缙云县|