使用@SpringBootTest禁用数据库连接

HIT*_*irl 6 hibernate jpa spring-boot-test

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

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

@SpringBootTest
class MyTest {

  @Autowired
  ....
}

Run Code Online (Sandbox Code Playgroud)

das*_*nse -1

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

@TestPropertySource(locations="classpath:test.properties")
Run Code Online (Sandbox Code Playgroud)

@TestPropertySource 快速指南