@Component
public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor{
private static final List<String> LAZY_BEANNAMES = new ArrayList<String>();
private static ConfigurableListableBeanFactory STATIC_FAC;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
STATIC_FAC = beanFactory;
String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
if(beanDefinitionNames == null) {
return;
}
Arrays.asList(beanDefinitionNames).forEach(beanDefinitionName -> {
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName);
if(beanDefinition.isLazyInit()) {
LAZY_BEANNAMES.add(beanDefinitionName);
}
});
}
public static List<String> getLazyBeannames() {
return LAZY_BEANNAMES;
}
public static BeanDefinition getBeanDefition(String beanName) {
return STATIC_FAC.getBeanDefinition(beanName);
}
}
网友评论