Load environment-specific properties for use with PropertyPlaceholderConfigurer?

后端 未结 8 1189
夕颜
夕颜 2020-12-23 17:24

This seems like a pretty common problem, but I haven\'t found any sort of consensus on the best method, so I\'m posing the question here.

I\'m working on a command-l

8条回答
  •  旧时难觅i
    2020-12-23 17:32

    Spring Property Placeholder Configurer – A few not so obvious options

    
        
    
    
        
        
        
        
    
    

    ${db.username.${mode}}: Here "mode" defines the project mode (environment) - dev / prod Properties file looks like:

    #Database properties
    #mode dev/prod
    mode=dev
    
    #dev db properties
    db.url.dev=jdbc:mysql://localhost:3306/dbname
    db.username.dev=root
    db.password.dev=root
    
    #prod db properties
    db.url.prod=jdbc:mysql://localhost:3306/dbname
    db.username.prod=root
    db.password.prod=root
    

提交回复
热议问题