Announcement Announcement Module
Collapse
No announcement yet.
Different Configuration for Test and Production Environments Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

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

    Comment


    • #3
      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?

      Comment


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

        Comment


        • #5
          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>

          Comment


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

            Comment


            • #7
              I used the method Kenan suggested and it works.
              Thanks to everyone who responded.

              Comment


              • #8
                thanks Kenan, pretty solution, it works..

                Comment


                • #9
                  Different Configuration for Test and Production Environments

                  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.

                  Comment


                  • #10
                    Different Configuration for Test and Production Environments

                    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...

                    Comment

                    Working...
                    X