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

后端 未结 8 2215
终归单人心
终归单人心 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:24

    I had to do it several times and the best approach I found is to configure an external directory as classpath resource in the container:

    Then, in the directory place the resources you want to externalize and everything will run fine. To load the resource in spring, you could do this way:

    
                
                
                
            
    

    You can see that, as you said that you might want to have multiple applications deployed in each tomcat, you could simply create a directory structure in the folder you set in classpath, to maintain different application.properties for each of your war applications

    In case you want to maintain dinamically the application name section in your Spring configuration, you could do it in several ways, during packaging stage in maven or even using the application context path

提交回复
热议问题