Handling of configuration files in Spring web applications

前端 未结 3 1842
南方客
南方客 2021-02-06 00:11

I have several times ran into the same problem, and I would like to have some input on what other people think about the issue: Suppose we have Spring application packaged as a

3条回答
  •  臣服心动
    2021-02-06 00:55

    Environment variable, external config files

    We have something similar, a Web Application running in Tomcat/Weblogic with Spring. What we do is define a environment property CONFIG_PATH and put all the XMLs (including spring config) and properties files in that directory.

    We have multiple properties files (per environment) that we send it as a tar file. The Web app loads all the Properties/Spring config files from the CONFIG_PATH directory. This variable is defined as Environment variable in the respective environment

    This way we are not touching the WAR file nor building separate WAR for environment. Think of this scenario: QA & PROD WAR files built, QA tested QA war file, PROD WAR deployed in PROD but something blows up :(

    We do something as below:

    In spring config xml, we define:

    
        
        
            
                file:${CONFIG_PATH}/App.properties
            
        
    
    

    Refer all variables as usual in spring config.

    In web.xml we define spring config as below:

    
        org.springframework.web.context.ContextLoaderListener
        
    
    
    
        contextConfigLocation
        file:${CONFIG_PATH}/**/spring-config.xml
        
    
    

    The QA/PROD team deploys the same artifact with their corresponding environment files. If something blows up we know its only the env. properties that are messed up. HTH

提交回复
热议问题