首页 > 编程语言 > 详细

spring 打印所有创建的beans

时间:2018-09-14 22:28:57      阅读:227      评论:0      收藏:0      [点我收藏+]

1,创建一个类,实现接口 BeanPostProcessor


package com.zuikc.web.controller;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class GetBeansNames implements BeanPostProcessor {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean; // we could potentially return any object reference here...
}
//在创建bean后输出bean的信息
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("Bean ‘" + beanName + "‘ created : " + bean.toString());
return bean;
}
}

2,在application.xml 中加入刚才创建的类名的bean
<bean class="com.zuikc.web.controller.GetBeansNames" />

3,在启动tomcat的时候就会打印创建beans的名称

spring 打印所有创建的beans

原文:https://www.cnblogs.com/albertzhangyu/p/9649080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!