There is no qualification bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' available

In a Java project, I am using Sprig Boot 1.5.3.RELEASE. It connects to two databases, i.e., MongoDB and Microsoft SQLServer. When I run it with spring-boot: run , it works fine. However, when I try to run it using the package , the error below is reported in test cases, despite the fact that these test cases do not connect to the SQL Server database:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467) ..... ..... 

MediationTest.java (Java class containing test cases generating the above errors)

 @RunWith(SpringRunner.class) @DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class) @SpringBootTest(classes = { Application.class }) public class MediationTest { @Autowired private SwiftFormat swiftFormat; ...................... ...................... 

Msqldbconfig.java

 @Configuration @EnableTransactionManagement @EnableJpaRepositories(entityManagerFactoryRef = "msqlEntityManagerFactory", transactionManagerRef = "msqlTransactionManager", basePackages = { "com.msql.data" }) public class MsqlDbConfig { @Bean(name = "msqlDataSource") @ConfigurationProperties(prefix = "msql.datasource") public DataSource dataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "msqlEntityManagerFactory") public LocalContainerEntityManagerFactoryBean msqlEntityManagerFactory( EntityManagerFactoryBuilder builder, @Qualifier("msqlDataSource") DataSource dataSource) { return builder.dataSource(dataSource) .packages("com.utils.msql.info") .persistenceUnit("msql").build(); } @Bean(name = "msqlTransactionManager") public PlatformTransactionManager msqlTransactionManager( @Qualifier("msqlEntityManagerFactory") EntityManagerFactory msqlEntityManagerFactory) { return new JpaTransactionManager(msqlEntityManagerFactory); } } 

application.properties

 spring.data.mongodb.uri=mongodb://dev-abc-123:27017/db msql.datasource.url=jdbc:sqlserver://ABC-SQL14-WXX;databaseName=dev msql.datasource.username=dev msql.datasource.password=***** msql.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver msql.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.show-sql=true 
+5
source share
1 answer

The purpose of spring-boot: run is determined by Mojo included in the spring-boot-maven-plugin project. You can find it here. https://github.com/spring-projects/spring-boot/blob/8e3baf3130220a331d540cb07e1aca263b721b38/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/socma/mooma java .

The requiresDependencyResolution scope is set to Test. This will include dependencies on each phase in the class path. Take a look at the specification here. https://maven.apache.org/developers/mojo-api-specification.html

The package goal provided by Maven will not include these additional dependencies in the classpath, and I believe this is causing your problems.

Spring Boot provides a repackage target that should be used to create spring-boot executable applications.

However, to find out more. I think that if you update your test to exclude an extra class, it might solve your problem.

@DataMongoTest(excludeAutoConfiguration = {EmbeddedMongoAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

+2
source

Source: https://habr.com/ru/post/1270013/


All Articles