How to externalize application.properties in Tomcat webserver for Spring?

后端 未结 8 2199
终归单人心
终归单人心 2020-12-10 01:59

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:



        
相关标签:
8条回答
  • 2020-12-10 02:31

    For me the easiest way to do it, was to place a context file inside Tomcat's config folder. For example if your application is running under root path (eg. http://your_domain.com/) you need to create a file [path_to_your_tomcat]/conf/Catalina/localhost/ROOT.xml. If your application runs in a different path, for example http://your_domain.com/example_path the file should be named like this [path_to_your_tomcat]/conf/Catalina/localhost/example_path.xml. Inside this file you can specify a path to the external application.properties file that can be placed anywhere on your hard drive.

    <?xml version="1.0" encoding="UTF-8"?>
    <Context>
        <Environment name="spring.config.location" value="file:/path/to/your/application/properties/file/" type="java.lang.String"/>
    </Context>
    
    0 讨论(0)
  • 2020-12-10 02:33

    if anyone is looking for a linux solution, This is working for us:
    edit tomcat startup.sh
    add:

     export spring_config_location=/<YOUR_PATH>/application.properties
    

    example:

     export spring_config_location=/app/conf/application.properties
    
    0 讨论(0)
提交回复
热议问题