我有一个 SpringBoot 应用程序。
我创建了这个测试:
@ContextConfiguration(classes={TestConfig.class})
@RunWith(SpringRunner.class)
@SpringBootTest
public class SuncionServiceITTest {
@Test
public void should_Find_2() {
// TODO
}
}
在哪里@Configuration
@EnableJpaRepositories(basePackages = "com.plats.bruts.repository")
@PropertySource("local-configuration.properties")
@EnableTransactionManagement
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class TestConfig {
}
和本地 configuration.properties
:spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa
但是当我运行测试时。我收到此错误:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
我也试过:
@EnableJpaRepositories(basePackages = "com.plats.bruts.repository", entityManagerFactoryRef="emf")
但后来我有错误:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'emf' available
最佳答案
看起来您缺少启动器依赖项。此启动依赖项具有配置 jpa
所需的所有必要依赖项。存储库。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
关于java - Spring Boot : Configuring Spring DataSource for Tests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64676649/