What am I doing wrong? I\'m using this little standalone App which runs and finds my src/main/resources/config/application.yml
. The same configuration doesn\'t work
The trick to load any custom yml file in SpringBoot 2.0 w/o using @SpringBootTest
ConfigFileApplicationContextInitializer
and spring.config.location
propertyExample Code:
@RunWith(SpringRunner.class)
@ContextConfiguration(
classes = { MyConfiguration.class, AnotherDependancy.class },
initializers = {ConfigFileApplicationContextInitializer.class} )
@TestPropertySource(properties = { "spring.config.location=classpath:myApp-test.yml" })
public class ConfigProviderTest {
@Autowired
private MyConfiguration myConfiguration; //this will be filled with myApp-test.yml
@Value("${my.config-yml-string}")
private String someSrting; //will get value from the yml file.
}
For JUnit 5 use the @ExtendWith(SpringExtension.class)
annotation instead of @RunWith(SpringRunner.class)