码迷,mamicode.com
首页 > 编程语言 > 详细

spring 打印所有创建的beans

时间:2018-09-14 23:14:19      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:ica   就会   ring   create   public   pos   string   ESS   could   

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

标签:ica   就会   ring   create   public   pos   string   ESS   could   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!