Announcement Announcement Module
No announcement yet.
Spring / Hibernate / Websphere Loading different properties files by environment Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring / Hibernate / Websphere Loading different properties files by environment


    Trying to set up a clean way of deploying my Spring / Hibernate app in Webshpere portal without having to modify the database connection info as we deploy from DEV on through to PRODUCTION.

    We have an environment variable defined in Websphere that can be looked up via JNDI to determine what set of properties need to be loaded.

    Can I somehow reference this JNDI variable in the Spring configuration and have it then inject the Hibernate sessionFactory using a file that is specific for the given environment ?? (DEV, QA, PROD) etc.


  • #2
    If you are on Spring 3.1 that is quite easy. Use an ApplicationContextInitializer which detects that name and enables the correct profile. If you aren't it might become more problematic, if instead of a JNDI variable it would be a system variable you could simply use a PropertyPlaceHolderConfigurer to replace the variable.

    Which reminds me you could add a PPHC and set the property based on the value from JNDI by setting the properties variable on the PPHC.


    • #3
      Thanks Marten,

      Running on Spring 3.0.6 so I suppose the ApplicationContextInitializer is not an option.

      I've been looking at the PPHC ... it's a bit unclear to me how I would get the JNDI variable and then use it to set the properties variable on the PPHC ...

      I'll keep looking around, if you could provide a quick example that would be a lifesaver.


      • #4
        <bean class="PropertyPlaceHolderConfigurer">
          <property name="properties>
              <prop key="environment><jee:jndi-lookup jndi-name="path/to/your/property"/></prop>
        Something like that (from the top of my head).