Spring boot with scheduler-BeanCreationNotAllowedException: Error creating bean with name 'entityManagerFactory': Singleton bean creation not allowed

▼魔方 西西 提交于 2019-12-04 07:16:36

In Spring Boot, when you do a maven build the test cases are run by default. In this scenario the integration test scripts are run which will be trying to connect to your database. Since you dont have anything to be excecuted as part of integration test in your project. One possible solution is to declare your class ProvisioningApplicationTests as abstract. This will restrict the instance creation of ProvisioningApplicationTests class.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ProvisioningApplication.class)
public abstract class ProvisioningApplicationTests {
    @Test
    public void contextLoads() {
    }
  }

The other way to solve this issue is to include the below code in your pom.xml

<plugins>
   <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
     <skipTests>false</skipTests>
     <excludes>
      <exclude>**/*IT.java</exclude>
     </excludes>
    </configuration>
   </plugin>
   <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <executions>
     <execution>
      <id>integration-test</id>
      <goals>
       <goal>integration-test</goal>
      </goals>
      <configuration>
       <skipTests>true</skipTests>
       <includes>
        <include>**/*IT.class</include>
       </includes>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>

This will exclude your integration test classes to be executed while building youy project. maven-surefire-plugin is use to run unit tests. maven-failsafe-plugin is use to run integration tests. While using this approach make sure that all your integration class file names ends with 'IT'. E.g. UserTestIT.java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!