Page 1 of 2 12 LastLast
Results 1 to 10 of 21

Thread: System configuration per environment

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default System configuration per environment

    My current client has 4 different application environments. When promoting to another environment, they do not allow rebuilds of the archive. They simply just take the war, in my case, and place it in the next environment. The issue here is that certain environmental properties must change without a rebuild. For example, the application sends out emails to the user's inviting them with a link to the web site. Unfortunately this link is different per environment.

    I have considered having an environment system property with possible values of dev, qa, or prod and reading in the appropriate properties file based on it's value. This approach will work but is there a better, more standard solution to this issue? Thanks.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You can configure the environment properties using JNDI. This should allow to deploy the war unchanged.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Location
    Auburn, AL, USA.
    Posts
    106

    Default

    You can also you the BeanFactoryPostProcessor to set the values of Spring managed JavaBeans based on system properties. If the JVM has standard properties set, then you can grab those and use them in this manner. Or you could have 4 different beans, and using property name to in setup:
    Code:
    <bean id="devEmailBean" .../>
    <bean id="qaEmailBean" .../>
    
    <bean id="emailManager" class="...">
        <property name="emailBean"><ref bean="$&#123;system.envType&#125;EmailBean"/></property>
    </bean>
    (where system.envType is the name of the system property).


    Also, as I understand it there are a solutions for scripting a Spring configuration (so you could turn on/off beans using this). Spring also has JNDI wiring support to assist you if you choose to go that route.

  4. #4
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    I like the simplicity of setting the values of beans based on system properties. I am wondering what other scripting variables are available when using an XML application context? Is there some documentation out there on using these variables?

    I have to admit, I am somewhat confused on how JNDI can allow me to change settings based on my environment. In my mind I would still need some kind of env system property to pivot on. Am I missing something?

    Thanks for your help.

    -karl
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  5. #5
    Join Date
    Aug 2004
    Location
    Auburn, AL, USA.
    Posts
    106

    Default

    Lookup: org.springframework.beans.factory.config.PropertyP laceholderConfigurer. For the most part you have to set the properties your self.

    At some point you'll need to get a property from somewhere - a properties file, a database, JNDI... With JNDI (which I am by no means an expert on) I think the simplest thing would be to use it to store a propety name/value pair, which your code would then lookup by name. While there are all sorts of 'different' options at some point they do boil down reading in a configuration property from somewhere; which is best depends on lots of things, but mainly how your code is structured, and on what server environment you will be deploying to; you obviously want to work with the tools and within the constraints of both.

  6. #6
    Join Date
    Sep 2004
    Location
    San Diego, CA
    Posts
    49

    Default

    I use the JNDI approach. I bound a java.util.Properties object into our app server's JNDI tree, configuring it from a properties file located outside of the war file. The specifics on how to do this depend on your application server.

    For different environments, you'd just use a different properties file. The JNDI object is configured and bound at app-server startup.

    This properties JNDI object can be accessed by your app directly via JNDI, or given to a PropertyPlaceHolderConfigurer like so:
    Code:
      <bean id="propertyResourceConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="properties"><ref local="config" /></property>
      </bean>
      <bean id="config" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>config/Properties</value></property>
        <property name="resourceRef"><value>true</value></property>
      </bean>
    where "config/Properties" is the JNDI name defined in web.xml and mapped in the appserver-specific web xml file.

    Then you can configure your beans by using ${property} throughout your application context as mentioned by other posters.


    Tim

  7. #7
    Join Date
    Nov 2007
    Posts
    6

    Default

    Hello ,

    this solution sounds very interesting. I am at the same point but have some problems to configure JNDI on Bea weblogic to access properties files outside the war file? Is there any simple way to do it?

    Thanks for any help!

    Quote Originally Posted by timmorrow View Post
    I use the JNDI approach. I bound a java.util.Properties object into our app server's JNDI tree, configuring it from a properties file located outside of the war file. The specifics on how to do this depend on your application server.

    For different environments, you'd just use a different properties file. The JNDI object is configured and bound at app-server startup.

    This properties JNDI object can be accessed by your app directly via JNDI, or given to a PropertyPlaceHolderConfigurer like so:
    Code:
      <bean id="propertyResourceConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="properties"><ref local="config" /></property>
      </bean>
      <bean id="config" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>config/Properties</value></property>
        <property name="resourceRef"><value>true</value></property>
      </bean>
    where "config/Properties" is the JNDI name defined in web.xml and mapped in the appserver-specific web xml file.

    Then you can configure your beans by using ${property} throughout your application context as mentioned by other posters.


    Tim

  8. #8

    Default

    Quote Originally Posted by timmorrow View Post
    I use the JNDI approach. I bound a java.util.Properties object into our app server's JNDI tree, configuring it from a properties file located outside of the war file. The specifics on how to do this depend on your application server.

    For different environments, you'd just use a different properties file. The JNDI object is configured and bound at app-server startup.

    This properties JNDI object can be accessed by your app directly via JNDI, or given to a PropertyPlaceHolderConfigurer like so:
    Code:
      <bean id="propertyResourceConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="properties"><ref local="config" /></property>
      </bean>
      <bean id="config" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>config/Properties</value></property>
        <property name="resourceRef"><value>true</value></property>
      </bean>
    where "config/Properties" is the JNDI name defined in web.xml and mapped in the appserver-specific web xml file.

    Then you can configure your beans by using ${property} throughout your application context as mentioned by other posters.


    Tim

    I like this idea, and you could take it one step further, by defining a local properties object as the 'defaultObject' property of the JndiObjectFactoryBean. This way, if the JNDI environment is unavailable as it would be in a unit test or local non-server environment, it will fall back to localized settings.

  9. #9
    Join Date
    Nov 2007
    Posts
    6

    Default

    For loading the properties file is the solution with RuntimeEnvironmentPropertiesConfigurer more fliexible than with JNDI.
    you can put your file anywhere and don't need to configure the JNDI on the appserver.

    thanks!

  10. #10

    Question

    I have a similar desire - I posted about it here: http://forum.springframework.org/showthread.php?t=46504
    "Conditional importing/loading of alternate beans.xml - environment specific beans"

    Basically I want to conditionally instantiate my JNDI beans dependant on environment - basically in test there's no JNDI. You can use <import> tags with ${} system properties, *but* I want it to default to a default import if the system property is not set.

Similar Threads

  1. Environment Variables in Spring?
    By dleal in forum Container
    Replies: 14
    Last Post: Apr 12th, 2007, 06:33 AM
  2. Dynamic Property Configuration
    By fenrick in forum Container
    Replies: 3
    Last Post: May 12th, 2006, 02:38 AM
  3. Replies: 3
    Last Post: Oct 5th, 2005, 08:39 AM
  4. Replies: 0
    Last Post: Jun 21st, 2005, 06:17 AM
  5. Replies: 5
    Last Post: Aug 27th, 2004, 07:13 PM

Posting Permissions

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