欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

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

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

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比冷水江網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式冷水江網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋冷水江地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。

一 配置文件

<?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">
   <!-- 配置兩個簡單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());
  }
  // 下面是兩個生命周期方法
  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
{
  /**
   * 重寫該方法,對Spring進(jìn)行后處理。
   * @param beanFactory Spring容器本身
   */
  public void postProcessBeanFactory(
    ConfigurableListableBeanFactory beanFactory)
    throws BeansException
  {
    System.out.println("程序?qū)pring所做的BeanFactory的初始化沒有改變...");
    System.out.println("Spring容器是:" + beanFactory);
  }
}

五 測試類

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容器
    // 它會自動注冊容器后處理器、Bean后處理器
    ApplicationContext ctx = new
      ClassPathXmlApplicationContext("beans.xml");
    Person p = (Person)ctx.getBean("chinese");
    p.useAxe();
  }
}

六 測試結(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緩存操作技巧匯總》

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

文章標(biāo)題:Spring實(shí)戰(zhàn)之容器后處理器操作示例
分享路徑:http://aaarwkj.com/article20/igisjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google外貿(mào)建站、網(wǎng)站營銷、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計、定制網(wǎng)站

廣告

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

網(wǎng)站托管運(yùn)營
尤物资源视频在线观看| 香婷婷一区二区精品久久| 久草免费福利视频资源站| 关于男女性生活的视频| 播放欧美日韩特黄大片| 久久精品人妻少妇一区二 | 欧美日韩国产天堂一区| 成年女人毛片免费观看不卡| 午夜福利激情视频在线| 国产福利成人一区二区| 国产女片xb内射在线| 国产精品日韩理论在线| 国产又爽又乱的视频在线| 日韩欧美国产亚洲在线| 亚洲av一区二区三区色多多| va精品人妻一区二区三区| 亚洲av天堂在线观看| 伊人久久大香线蕉av网站| 国产精品日韩精品在线| 色偷偷91综合久久噜噜| 亚洲一区欧美日韩91| av国产剧情在线观看| 国产91啦中文在线观看| 久久日韩制服丝袜人妻| 伊人欧美一区二区三区| 91成年精品一区在线观看| 色老头视频一区二区三区 | 91九色在线视频观看| 黄片在线免费在线播放| 中文字幕国产精品欧美| 一区二区三区四区中文在线| 人体蜜桃视频一区二区| 免费观看国产性生活片| 国语av一区二区三区| 夫妻性生活视频一级片| 中文字幕在线看二区不卡| 亚洲一区二区视频免费看| 激情久久五月激情婷婷| 国产三级网站在线观看播放| 日本亚洲一区二区在线| 日韩精品在线观看视频一区二区三区|