How to override application.properties during production in Spring-Boot?

后端 未结 8 851
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 13:00

I\'m using spring boot and application.properties to select a database during development by @Configuration @Profile(\"dev\").

spri         


        
8条回答
  •  遥遥无期
    2020-12-04 13:42

    Update with Spring Boot 2.2.2.Release.

    Full example here, https://www.surasint.com/spring-boot-override-property-example/

    Assume that, in your jar file, you have the application.properties which have these two line:

    server.servlet.context-path=/test
    server.port=8081
    

    Then, in production, you want to override the server.port=8888 but you don't want to override the other properties.

    First you create another file, ex override.properties and have online this line:

    server.port=8888
    

    Then you can start the jar like this

    java -jar spring-boot-1.0-SNAPSHOT.jar --spring.config.location=classpath:application.properties,/opt/somewhere/override.properties
    

提交回复
热议问题