Consider defining a bean named 'entityManagerFactory' in your configuration after Update from Spring Boot 2.2.7

Viewed 84

After upgrading from Spring Boot Version 2.2.7.RELEASE to 2.7.3 we get the error when we try to start our application.

2022-09-22 11:20:31.896  WARN 60031 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'bookApi'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookApi': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': Cannot create inner bean '(inner bean)#4b3fe06e' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4b3fe06e': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2022-09-22 11:20:31.898  INFO 60031 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-09-22 11:20:31.908  INFO 60031 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-22 11:20:31.941 ERROR 60031 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field repository in com.example.module.api.BookApi required a bean named 'entityManagerFactory' that could not be found.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

Background

We modularized our application with JPMS, and we start our application with the following command:

java --module-path ./mods:./lib -m app/com.example.app.AppApplication

We copy our application jars to ./mods (with the maven-jar-plugin) and all runtime dependencies to ./lib (with the maven-dependency-plugin).

This works perfectly with Java 11 and with the Spring Boot "2.2.7.RELEASE", but starting with the release "2.2.8.RELEASE" the same project leads to the above error. We get the same error even if we upgrade to the newest Spring Boot Version 2.7.3

Reproducible Examples

To reproduce in a small but running example. I created a jpms application and uploaded a working version (Spring Boot 2.2.7.RELEASE) to the main branch and the non-working version (Spring Boot 2.2.8.RELEASE) to the spring-boot-2.2.8.RELEASE branch.

The project URL is: https://github.com/rudolfgrauberger/jpms-multi-modules-example

Edit: I added the new branch spring-boot-2.7.3-java17 to show the issue with the newest version of Spring Boot and the LTS-Version of Java.

Question

Anyone have any idea how I can find out what exactly the problem is or what has changed between the versions (especially with the EntityManager or with @EnableJpaRepositories)?

I have already searched the Announcement for 2.2.8.Release, the Release Notes for changes and also used the search engine very intensively but I don't found anything regarding to this problem/change.

Happy to share more information, just need to know what exactly would be helpful

0 Answers
Related