问题描述
今日在开发过程中遇到一个spring configuration类注入失败的问题,具体代码如下:
@Configuration
@Import({
TestBean1.class})
public class HelloConfiguration {
@Resource
private ApplicationContext applicationContext;
@Bean
public TestBean2 testBean2() {
TestBean1 testBean2 = applicationContext.getBean(TestBean1.class);
return new TestBean2();
}
@Bean
public TestBeanDefinitionRegistryPostProcessor testBeanDefinitionRegistryPostProcessor() {
return new TestBeanDefinitionRegistryPostProcessor();
}
}
执行过程中抛出如下异常NullPointerException:
Caused by: java.lang.NullPointerException
at com.example.demo.config.HelloConfiguration.testBean2(HelloConfiguration.java:27) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native