Search code examples
javaspringjndi

How to use JndiPropertySource?


We are trying to convert our WebApp to complete configuration using a JndiPropertySource(for all parameters that are environment dependent).

Has anyone a example usage of it (maybe even for tomcat)?

We already get the DataSource via JNDI, so we want the HibernateDialect to be configured right besides it...


Solution

  • In your spring-context.xml you need only the placeholder tag:

    <context:property-placeholder />
    

    After that you insert an environment tag in Tomcats main context.xml, it reads it:

    <Environment name="hibernate.dialect" 
                value="org.hibernate.dialect.Oracle10gDialect" 
                 type="java.lang.String" 
             override="false"/>
    

    Now you can use the code ${hibernate.dialect} in the sprinng config file.