Reputation: 97517
I have a larger Spring Boot Application(Nr.1) which comprises of several modules about 20+ (multi module setup).
Inside that I have another Spring Boot Application (Nr.2) which contains several services etc.
app-1
+...
module-jpa
+-- pom.xml
+-- src/main/java/jpa/ (JPA Classes; Entities etc.)
module-repos
+-- pom.xml
+-- src/main/java/repos/ JPA Repositories; XYZ extends CrudRepository<..>.
module-app
+-- pom.xml (dependency on module-jpa and module-repos)
+-- src
+-- main
+-- java
+-- xyz
+-- application
+-- SpringBootApp.java
+-- services
+-- Service1.java
+-- Service2.java
+-- src
+-- test
+-- java
+-- services
+-- Service1IT.java
+-- Service2IT.java
+-- resources
+-- application.properties
In the above constellation the integration tests are running fine (Service1IT and Service2IT).
Now I have refactored module-app
into two separate modules module-app
and module-app-cli
cause I wanted to reuse module-app
. The result looks like the following:
module-app
+-- pom.xml (dependency on module-jpa and module-repos)
+-- src
+-- main
+-- java
+-- services
+-- Service1.java
+-- Service2.java
+-- src
+-- test
+-- java
+-- services
+-- Service1IT.java
+-- Service2IT.java
+-- resources
+-- application.properties
module-app-cli
+-- pom.xml (dependency on module-jpa, module-repos, module-app)
+-- src
+-- main
+-- java
+-- xyz
+-- application
+-- SpringBootApp.java
+-- resources
+-- application.properties
But now the integration tests for Service1IT.java
etc. are not working anymore with exceptions like:
xyzTest(xyz.abcIT) Time elapsed: 0.141 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'firstService':
Unsatisfied dependency expressed through field 'secondService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '.........'repos.ABCRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
What I don't understand is at the moment that just by separating the SpringBootApp
into a separate module results in failing integration Tests which are not related to the SpringBootApp.java
but based on the result it looks they are related? The question is: Can this be solved?
I suppose I oversight something which is not clear to me? Does someone has a suggestions what could cause that behaviour?
Some details:
Using Spring Boot Version 2.1.3.RELEASE
If you need more informations please leave a comment.
Update 1
I'm just trying other ways to fix the issue. So I have started from the beginning and just removed the main SpringBootApp class from module-app
and removed also the call to spring-boot-maven-plugin in the pom.xml file and the result is simply:
service1IT(services.Service1IT) Time elapsed: 0.004 s <<< ERROR!
java.lang.IllegalStateException:
Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'xyzService': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'javax.persistence.EntityManagerFactory' available
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'javax.persistence.EntityManagerFactory' available
Upvotes: 1
Views: 226
Reputation: 97517
So after analysing this in depth I found out that the tests lacking the @EnableAutoConfiguration
annotation which solved the issue (except from others) but this was the most important one.
Upvotes: 1