Spring Boot - Environment @Autowired throws NullPointerException

前端 未结 4 1187
攒了一身酷
攒了一身酷 2020-11-30 07:46

I have a project setup using Spring Boot 0.5.0.M5.

In one of the configuration files I am trying to @Autowire Environment but that fail

4条回答
  •  鱼传尺愫
    2020-11-30 08:36

    I believe there were some lifecycle issues with Spring and the EntityManagerFactory, and you might have fallen foul of those (fixed in 4.0.0.RC1) - if your @Configuration class gets instantiated super early, it might not be eligible for autowiring. You can probably tell from the log output if that is the case.

    Just out of interest, did you know that the functionality provided by your JpaConfig and PropertyConfig is already presetn out of the box if you use @EnableAutoConfiguration (as long as you @ComponentScan that package where your repositories are defined)? See the JPA sample in Spring Boot for an example.

提交回复
热议问题