---
title: "spring 监听bean 加载"
author: "yaoweinan"
date: "2011-12-20T08:58:39Z"
tags: []
categories: ["编程语言"]
slug: "spring-bean"
draft: false
lastmod: "2011-12-20T08:58:39Z"
id: 1317299
url: "https://ilyon.iteye.com/blog/1317299"
---

package com.until;

import org.springframework.beans.BeansException;  
import org.springframework.beans.factory.config.BeanPostProcessor;  
import org.springframework.context.ApplicationEvent;  
import org.springframework.context.ApplicationListener;

/\**  
 * 测试类   打印出加载的bean  
 * @author Administrator  
 *  
 \*/  
public class SpringBeanInitProcesser implements BeanPostProcessor {

 public Object postProcessAfterInitialization(Object bean, String beanName)  
   throws BeansException {  
  // TODO Auto-generated method stub  
  //System.out.println("Bean '" + beanName + "' created : " + bean.toString());  
  return bean;  
 }

 public Object postProcessBeforeInitialization(Object bean, String beanName)  
   throws BeansException {  
  // TODO Auto-generated method stub  
  System.out.println("Bean '" + beanName + "' created : " + bean.toString());  
  return bean;  
 }

}