We have a JPA @Entity with @EntityListeners(MyJpaListener.class) that have fields that have @Autowired annotations which are properly injected since we have @Configuration, @Bean, and @Component annotations in the right places. This worked fine in Spring Boot 2.3.4 to 2.3.6, but after upgrading to 2.3.7 and 2.3.8, our app is now throwing NullPointerException (NPEs) in our custom JPA Listener for the autowired field. We are also using Hibernate and Postgres. Our Entity Listener has the JPA @PostPersist annotation on the method that is fired where the NPE happens.

We believe there is a change in Spring Data or Spring Data JPA that broke this behavior (doing diff between the Spring Boot 2.3.6 and 2.3.7 POMs show that spring-data-releasetrain.version was upgraded from Neumann-SR5 to Neumann-SR6 which causes this regression.

Comment From: nngo

Our JUnit unit tests were also failing with NPEs b/c nulls on the @Autowired fields in our customer JPA Listener, it was running with the JUnit 5 vintage engine, but we were able to get them running by switching to using the JUnit 5 runner by importing org.junit.jupiter.api.Test instead of org.junit.Test (JUnit 4).

Comment From: wilkinsona

Thanks for the report. We're not aware of any problems in this area. I would be surprised if Spring Data (JPA) is the cause of the problem. As far as I know, it isn't involved in dependency injection into Entity classes. If you would like us to spend some time investigating the cause of the problem, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: nngo

In an attempt to rework code to do constructor autowiring in attempt to fix this issue under Spring Boot 2.3.8, we got following error: "The dependencies of some of the beans in the application context form a cycle". We are able to workaround this by updating one of our dependency injected bean/class to not have a circular dependency: i.e. it depends on a Service that depends on a Repository which depends on entityManagerFactory and so forth. Somehow, that circular dependency/cycle worked under Spring Boot 2.3.4, 2.3.5, and 2.3.6, but not under 2.37 or 2.3.8.

If I have sometime, I will try to put together a small reproducible project for this issue.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.