Spring-boot not using application.properties in tests

I have a project with spring, hibernate and flyway to create a database schema. So i

spring.jpa.hibernate.ddl-auto: validate 

in my application.properties file. This configuration works during normal startup (after packing the executable jar file and launching it from the terminal):

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

but when running tests through maven it is ignored.

 1804 [main] INFO ohtool.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 ohtool.hbm2ddl.SchemaExport - HHH000230: Schema export complete 

The main difference from the official flyout seems to be that I don't use spring-boot provided by maven-parent.

Full project here

+6
source share
2 answers

Your test does not use Spring Boot (it needs to use @SpringApplicationConfiguration instead of @ContextConfiguration or declare appropriate listeners).

+14
source

You must define ConfigFileApplicationContextInitializer to include the application.properties file in your integration test. Just change your annotation to:

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

I sent you a transfer request with this small change.

+4
source

Source: https://habr.com/ru/post/976283/


All Articles