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

后端 未结 8 852
隐瞒了意图╮
隐瞒了意图╮ 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:52

    I know you asked how to do this, but the answer is you should not do this.

    Instead, have a application.properties, application-default.properties application-dev.properties etc., and switch profiles via args to the JVM: e.g. -Dspring.profiles.active=dev

    You can also override some things at test time using @TestPropertySource

    Ideally everything should be in source control so that there are no surprises e.g. How do you know what properties are sitting there in your server location, and which ones are missing? What happens if developers introduce new things?

    Spring Boot is already giving you enough ways to do this right.

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

提交回复
热议问题