Results 1 to 10 of 10

Thread: Different Configuration for Test and Production Environments

  1. #1

    Default Different Configuration for Test and Production Environments

    Greetings,

    I would like to consult with you about the best way to implement usage of different configuration data at different environments.
    Specifically, I have several Spring JAX-WS client beans (JaxWsPortProxyFactoryBean, chapter 17.5.8 in the documentation). I want the wsdlDocumentUrl property to point at different URLs at test and production environments, and I can't think of a pretty way to do it.
    Does anyone have any suggestions?

    Thanks
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

  2. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    You could use a PropertyPlaceholderConfigurer, and places your environment specific settings in a property file.
    Bill

  3. #3

    Default

    Thanks for your reply Bill.
    I thought about it, but how do I tell Spring to use different properties files at different environments (without externalizing the properties files to the filesystem)? Is there a way to make Spring use a properties file according to the value of an environment variable for example?
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

  4. #4
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    I'm not entirely sure. I think people have asked about it in the past, but I don't remember what the resolution was.
    Bill

  5. #5

    Default

    I have pasted how we achieve this in our projects. It is pure spring configuration. target.platform is an environment variable. Therefore, we first provide a ganeral project.properties which contain configurations that apply to all applications, then a project specific extension file, and finally an environment specific properties file. Each file is processed in the order they are defined, so same properties are overriden by the later. Hope this helps...

    Code:
    <bean id="propertyLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
    	<property name="sourceList">
    		<list>
    			<value>classpath:project.properties</value>
    			<value>classpath:project.extension.properties</value>
    			<value>classpath:project.extension.${target.platform}.properties</value>
    		
    		</list>
    	</property>
    </bean>
    
    <bean id="projectProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    	<property name="locations" ref="propertyLocations"/>
    	<property name="ignoreResourceNotFound">
    		<value>true</value>
    	</property>
    </bean>
    
    <bean id="propertyPlaceholderConfigurer"
    	class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	<property name="properties" ref="projectProperties" />
    	<property name="systemPropertiesMode">
    		<ref local="PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    	</property>
    	<property name="searchSystemEnvironment">
    		<value>true</value>
    	</property>
    	<property name="ignoreUnresolvablePlaceholders">
    		<value>true</value>
    	</property>
    </bean>
    
    <bean  id="PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE" 
    		class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
    	  <property name="staticField">
    		   <value>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    	  </property>
    </bean>

  6. #6
    Join Date
    Mar 2007
    Location
    Poland
    Posts
    341

    Default

    If you are thinking of higher level of configuration switch look at
    http://blog.springsource.com/main/20...-obvious-talk/

  7. #7

    Default

    I used the method Kenan suggested and it works.
    Thanks to everyone who responded.
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

  8. #8
    Join Date
    Sep 2006
    Posts
    1

    Default

    thanks Kenan, pretty solution, it works..

  9. #9

    Default Different Configuration for Test and Production Environments

    Quote Originally Posted by miluch View Post
    If you are thinking of higher level of configuration switch look at
    http://blog.springsource.com/main/20...-obvious-talk/
    Thanks it really works.

  10. #10
    Join Date
    Jan 2011
    Location
    India
    Posts
    1

    Default Different Configuration for Test and Production Environments

    Quote Originally Posted by miluch View Post
    If you are thinking of higher level of configuration switch look at
    http://blog.springsource.com/main/20...-obvious-talk/
    Thanks for the link provided it works...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •