Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-boot not using application.properties in tests

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

spring.jpa.hibernate.ddl-auto: validate

in my application.properties file. This config works during normal run (after packaging the executable jar-file and running it from the terminal):

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

but is ignored when running tests via 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 

The main difference with the official flyway-sample seems in the I don't use the spring-boot provided maven-parent.

The complete project is here

like image 342
Ivan Sopov Avatar asked Oct 06 '14 06:10

Ivan Sopov


People also ask

Is application properties mandatory in spring boot?

So in a spring boot application, application. properties file is used to write the application-related property into that file. This file contains the different configuration which is required to run the application in a different environment, and each environment will have a different property defined by it.

How do I apply application properties in spring boot?

Step 1 − After creating an executable JAR file, run it by using the command java –jar <JARFILE>. Step 2 − Use the command given in the screenshot given below to change the port number for Spring Boot application by using command line properties.

Where does spring boot look for property file in test?

properties file in the classpath (src/main/resources/application. properties).

Does spring boot support application properties support?

Spring Boot provides another file to configure the properties is called yml file. The Yaml file works because the Snake YAML jar is present in the classpath. Instead of using the application. properties file, we can also use the application.


1 Answers

Your test isn't using Spring Boot (it needs to use @SpringApplicationConfiguration instead of @ContextConfiguration, or declare the appropriate listeners).

like image 151
Dave Syer Avatar answered Oct 12 '22 20:10

Dave Syer