Is there a way to specify a default property value in Spring XML?

后端 未结 7 918
傲寒
傲寒 2020-12-02 07:17

We are using a PropertyPlaceholderConfigurer to use java properties in our Spring configuration (details here)

eg:

         


        
7条回答
  •  鱼传尺愫
    2020-12-02 07:43

    There is a little known feature, which makes this even better. You can use a configurable default value instead of a hard-coded one, here is an example:

    config.properties:

    timeout.default=30
    timeout.myBean=60
    

    context.xml:

    
        
            config.properties
        
    
    
    
        
    
    

    To use the default while still being able to easily override later, do this in config.properties:

    timeout.myBean = ${timeout.default}
    

提交回复
热议问题