Common strategies when defining Spring beans for different environments

前端 未结 3 1972
逝去的感伤
逝去的感伤 2020-12-05 09:14

What are common strategies for defining a bunch of beans, which are used differently in development and production environments?

Let\'s say I have 2 beans, each impl

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 09:30

    Here goes what Spring reference documentation says about PropertyPlaceholderConfigurer

    The PropertyPlaceholderConfigurer does not look for properties only in the Properties file you specify, but also checks against the Java System properties if it cannot find a property you are trying to use.

    As you can see above you can set up a Java System property

    On The development machine

    -Dprofile=development
    

    On The production machine

    -Dprofile=production
    

    So you can define a global application context settings which import each layered context settings as follows

    
    
        
        
        
        
    
    

    Keep in mind all location paths are relative to the definition file doing the importing

    Therefore, This kind of configuration is supported by Spring

    It is generally preferable to keep an indirection for such absolute locations, for example, through "${...}" placeholders That are resolved against JVM system properties at runtime.

提交回复
热议问题