hibernate - 使用@SpringBootTest 禁用数据库连接

标签 hibernate jpa spring-boot-test

我有一个带有 hibernate 功能的 SpringBoot 应用程序。在我的测试中,我想禁用任何类型的数据库连接和配置(测试无权访问数据库)。我该怎么做?

我的测试类用 @SpringBootTest 注释并有 @Autowired特性。
禁用所有数据库交互的正确注释值是什么?

@SpringBootTest
class MyTest {

  @Autowired
  ....
}

最佳答案

您可以使用 @TestPropertySource覆盖 application.properties 中的值.

@TestPropertySource(locations="classpath:test.properties")

A Quick Guide to @TestPropertySource

关于hibernate - 使用@SpringBootTest 禁用数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58517307/

相关文章:

java - hibernate 中的部分架构导出

sql - 在什么情况下 SELECT by PRIMARY KEY 会很慢?

java - 如何从另一个实体获取字段的值(Hibernate)

java - 如何测试 Spring Boot 处理程序拦截器

java - Spring 启动 : How to override default properties in Unit tests

java - org.hibernate.MappingException : Could not determine type for: java. util.Collection,在表

Spring 3匹配的通配符很严格,但是找不到元素 'jee:jndi-lookup'的声明

java - 使用 hibernate 的一对一引用完整性

Java + JPA : Search User in Database By first and last name return too many results. 有更好的方法吗?

java - 在测试应用程序之前初始化 Spring Boot 测试 bean