Spring use one application.properties for production and another for debug

后端 未结 2 1995
盖世英雄少女心
盖世英雄少女心 2020-12-29 21:14

I have a Spring application and I would like to be able to switch between configurations depending if I\'m debugging the server or if the server is running in production. (t

相关标签:
2条回答
  • 2020-12-29 21:37

    You can have 3 properties files, application-dev.properties, application-prod.properties and application.properties. And you can specify all the development properties in your dev properties file and production cionfiguration properties in your prod file

    and specify the profile in your application.properties files as below

    spring.profiles.active=dev
    

    or you can select/override the profile using -Dprofile= argument in command line.

    0 讨论(0)
  • 2020-12-29 21:41

    Spring profiles seem the way to go. You can start your application with something like -Dprofile=. Have a look at this example.

    EDIT: after re-reading your question, I came to the conclusion that you might actually want something more basic: put your database properties externally. Depending on your application you could use @Value of a property configurator. Have a look at the spring docs.

    0 讨论(0)
提交回复
热议问题