Hibernate spring引导未在测试中使用application.properties

Hibernate spring引导未在测试中使用application.properties,hibernate,spring-boot,flyway,Hibernate,Spring Boot,Flyway,我有一个与spring、hibernate和flyway一起创建数据库模式的项目。所以我有 spring.jpa.hibernate.ddl-auto: validate 在my application.properties文件中。此配置在正常运行期间工作(打包可执行jar文件并从终端运行后): 但在通过maven运行测试时被忽略 1804 [main] INFO o.h.tool.hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schem

我有一个与spring、hibernate和flyway一起创建数据库模式的项目。所以我有

spring.jpa.hibernate.ddl-auto: validate
在my application.properties文件中。此配置在正常运行期间工作(打包可执行jar文件并从终端运行后):

但在通过maven运行测试时被忽略

1804 [main] INFO  o.h.tool.hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schema export 
1805 [main] DEBUG org.hibernate.SQL - drop table test_entity if exists 
1806 [main] DEBUG org.hibernate.SQL - drop sequence hibernate_sequence 
1807 [main] DEBUG org.hibernate.SQL - create table test_entity (id bigint not null, name    varchar(255), primary key (id)) 
1807 [main] DEBUG org.hibernate.SQL - create sequence hibernate_sequence 
1808 [main] INFO  o.h.tool.hbm2ddl.SchemaExport - HHH000230: Schema export complete 
与官方flyway示例的主要区别似乎在于maven父级提供的“我不使用spring引导”


整个项目是

您的测试没有使用Spring Boot(它需要使用
@SpringApplicationConfiguration
而不是
@ContextConfiguration
,或者声明适当的侦听器).

您应该定义配置文件ApplicationContextInitializer以将application.properties文件包括在集成测试中。只需将注释更改为:

@ContextConfiguration(classes = FlywaySpringBootTestApplication.class, initializers = ConfigFileApplicationContextInitializer.class)
我已经给你发了一个带零钱的请求

@ContextConfiguration(classes = FlywaySpringBootTestApplication.class, initializers = ConfigFileApplicationContextInitializer.class)