spring 打印所有创建的beans

2021-06-28 14:06

阅读:542

标签: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

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

spring 打印所有创建的beans

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

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


评论


亲,登录后才可以留言!