Spring boot external configuration of property file

后端 未结 4 1183
感动是毒
感动是毒 2020-12-03 05:29

I have a spring boot application that I can package in a war that I want to deploy to different environments. To automate this deployment it\'d be easier to have the configu

4条回答
  •  悲哀的现实
    2020-12-03 05:50

    Yes, you need to use @PropertySource as shown below.

    The important point here is that you need to provide the application_home property (or choose any other name) as OS environment variable or System property or you can pass as a command line argument while launching Spring boot. This property tells where the configuration file (.properties or .yaml) is exactly located (example: /usr/local/my_project/ etc..)

    @Configuration
    @PropertySource("file:${application_home}config.properties")//or specify yaml file
    @ComponentScan({"be.ugent.lca","be.ugent.sherpa.configuration"})
    @EnableAutoConfiguration
    @EnableSpringDataWebSupport
    public class Application extends SpringBootServletInitializer{
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    

提交回复
热议问题