What is the best way to manage configuration data

前端 未结 8 1169
时光取名叫无心
时光取名叫无心 2020-12-07 17:18

I am working on a product suite which has 4 products. Right now, all of the configuration data is either in the XML or properties files.This approach is not maintainable as

8条回答
  •  醉梦人生
    2020-12-07 18:01

    For all of our environments, configuration data lives on the target machines in the form of properties files. We use PropertyPlaceholderconfigurer from SpringFramework to bind these properties to our apps to keep things portable accross environments.

    For example, as long as I know that /etc/myapp/database.properties will be present on whatever machine my app will be running on, then in my spring configuration, I just need something like so:

        
        
            
                /etc/myapp/database.properties
            
        
    
    
        
        
        
             
    
    

    There are a bunch of options for that Spring class about where properties files can live. You can even make them substitutions and pass them in as environment variables:

        
        
        
        
            
                ${database.configuration.file.url}
            
        
    
    

    And in bash_profile (or whatever): export JAVA_OPTS="-Ddatabase.configuration.file.url=file:///etc/myapp/database.properties"

    Or just the same -D option passed in when you call "java" depending on what you are doing.

    FWIW, we maintain our properties files separately as RPMs.

提交回复
热议问题