How to programmatically tell `Spring Boot` to load configuration files from `custom location` when doing JUNIT Test -
how programmatically tell spring boot
load configuration yaml
files custom location
when doing junit test.
in program, use properties
of springapplicationbuilder
specify custom yaml
file .
@configuration @springbootapplication @componentscan public class samplewebapplication { public static void main(string[] args) { configurableapplicationcontext applicationcontext = new springapplicationbuilder(samplewebapplication.class) .properties("spring.config.name:application,conf", "spring.config.location=classpath:/viaenvironment.yaml") .build().run(args); configurableenvironment environment = applicationcontext.getenvironment(); system.out.println(environment.getproperty("app.name")); } }
when doing junit test, how should configure it? i'm using spring boot 1.5.1
.
please use option set spring.config.location through @testpropertysource:
@testpropertysource(properties = { "spring.config.location = classpath:<path-to-your-yml-file>" }
Comments
Post a Comment