環境指定のspring-boot run
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production"
環境を指定する
なんかまあこんな感じ。
src/main/java/Example.java
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration @Configuration @PropertySource("classpath:/config/application.yml") public class Example { @Autowired private Environment env; @RequestMapping("/") String home() { return env.getProperty("foo.bar"); } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); } }
src/main/resources/config/application.yml
foo: bar: "hello, development!"