2014-10-06 85 views
6

我有一个使用spring,hibernate和flyway的项目来创建数据库模式。所以我在我的application.properties文件中有在测试中没有使用application.properties的spring-boot

spring.jpa.hibernate.ddl-auto: validate 

。此配置在正常运行期间(在打包可执行jar文件并从终端运行之后)工作:

2014-10-06 10:06:17.863 INFO 7519 --- [   main] o.h.tool.hbm2ddl.SchemaValidator   : HHH000229: Running schema validator 

但在通过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-sample的主要区别似乎在我不使用spring-boot提供的maven-parent。

完整的项目为here

回答

14

您的测试没有使用Spring启动(它需要使用@SpringApplicationConfiguration代替@ContextConfiguration,或宣布相应的听众)。

4

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

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

我已经通过这个小改动向您发送了拉请求。

相关问题