Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 模块化Spring Boot 2应用程序导致集成测试失败_Java_Spring Boot_Java 8_Spring Boot Test - Fatal编程技术网

Java 模块化Spring Boot 2应用程序导致集成测试失败

Java 模块化Spring Boot 2应用程序导致集成测试失败,java,spring-boot,java-8,spring-boot-test,Java,Spring Boot,Java 8,Spring Boot Test,我有一个更大的Spring Boot应用程序(Nr.1),它由几个模块组成,大约20+(多模块设置) 在里面,我有另一个Spring Boot应用程序(Nr.2),它包含几个服务等 app-1 +... module-jpa +-- pom.xml +-- src/main/java/jpa/ (JPA Classes; Entities etc.) module-repos +-- pom.xml +-- src/main/java/repos/ JPA Repositor

我有一个更大的Spring Boot应用程序(Nr.1),它由几个模块组成,大约20+(多模块设置)

在里面,我有另一个Spring Boot应用程序(Nr.2),它包含几个服务等

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
但是现在
Service1IT.java
等的集成测试不再有效,出现以下异常:

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)}

因此,在深入分析之后,我发现测试缺少
@EnableAutoConfiguration
注释,该注释解决了问题(其他注释除外),但这是最重要的注释

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)}
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