关于@Configuration注解的思考

package org.spring.boot.example.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public final class RootConfig implements InitializingBean {

    public RootConfig() {
        System.out.println("============");
    }

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public MyBeanDefinitionRegistryPostProcessor myBeanDefinitionRegistryPostProcessor() {
        return new MyBeanDefinitionRegistryPostProcessor();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        String id = applicationContext.getId();
        System.out.println("id = " + id);
    }
}

package org.spring.boot.example.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}

以上这个类存在两个问题,你知道吗?又知道如何解决吗?以及其中的问题。

上一篇:redisson 导致spring boot 项目单元测试启动失败


下一篇:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.e3ma