Spring Boot 1.4 test loading yaml file from main resources

Konstantine

Before migrating our Spring Boot 1.3 application to 1.4, when running integration tests, we used to load our application-test.yml file from src/main/resources/config/ folder which would override properties from an application.yml file that was loaded from src/test/resources/config/ folder.

However, with the new version of Spring Boot and its test suite it seems that while bootstrapping the application for testing, it no longer checks the resources folder under src/main. It instead only checks the resources that are location under src/test/ and is looking for .yml files only under that folder's config/ folder.

Is there a way to tell Spring Boot that it should be looking for .yml files under both resources folders?

Yuri

It is better to have fully separated resources. Definitely, you should think about that. But, cut the long story short, you could try to do something like this:

@TestPropertySource(locations = {
   "classpath:test.yml",
   "classpath:test-override.yml" })

If you have *.yml, then don't forget to declare the following line above your class:

@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring Boot 2.0 JNDI property values not loading from application-test property file

Liquibase : link main yaml changelog from test

Gradle build: Exclude resources files from Spring Boot Jar file

How to access a resource file in src/main/resources/ folder in Spring Boot

Load resource/file from test/resources using Spring

Spring Boot access static resources missing scr/main/resources

Spring Boot: Load @Value from YAML file

resources in a Spring Boot application are missing from jar file when using Spring Boot Maven Plugin

Spring Boot properties in 'application.yml' not loading from JUnit Test

Can't load a test-properties.yaml file with the @TestPropertySource with Spring Boot, JUnit5 and Kotlin

How to instruct Spring Boot to use application.properties file in test's resources when running tests

Using actual properties file from src/main/resources with Spring @PropertySource in JUnit test

Spring Boot 2.1 : Not loading property from application-test.yml

Spring boot read array from YAML (properties) file

Spring boot reference file location from resources in properties file

Spring Boot: can't load file from resources

Spring @Value resource injection of test AND main resources

Spring Boot test with yaml properties by profile

Loading static resources with Spring Boot and Thymeleaf

Serving Static resources from file system | Spring Boot Web

Spring Boot MockMVC Test does not load Yaml file

Spring Boot - Injecting a map from a YAML file

Spring Boot loading a list from a config file returns empty list

How to read JSON file from resources in Spring Boot

read .html file from resources folder on server in spring boot

Spring 4 loading static resources

Loading file from /src/main/resources

Spring Boot: Load security roles from yaml file

My test cases in spring boot app are reading from main application.yaml file instead of application-test.yaml