Self contained JAR with Tomcat and JNDI placeholders

447 Views Asked by At

I'm in the process of transitioning the legacy Spring 3.2.8 application from WAR deployment to self-contained JAR. I'm using tomcat7-maven-plugin to create an executable JAR:

mvn install tomcat7:exec-war

Since the application uses JNDI placeholders, it obviously fails to run without them defined. In Tomcat installation following placeholders are defined: (conf/Catalina/localhost/myapp.xml):

<Resource name="jdbc/mediaagent" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/mediaagent" username="user" password="password"/>
<Environment name="hibernate/dialect" type="java.lang.String" value="PostgreSQL" />

The context.xml which is packaged in WAR, has following placeholder references:

<ResourceLink name="jdbc/mediaagent" global="jdbc/mediaagent" type="javax.sql.DataSource"/>
<ResourceLink name="hibernate/dialect" global="hibernate/dialect" type="java.lang.String"/>

Finally, these placeholders are used in applicationContext.xml in the following way:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/mediaagent"/>
</bean>



    <bean id="dataSourceProperties"
              class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
                <props>
                ...
                    <prop key="hibernate.dialect">org.hibernate.dialect.${dialect}Dialect</prop>
                ...
                </props>
            </property>
        </bean>

My goal is to extract these settings to separate configuration file which should be placed next to the self-contained JAR, preferably properties file as in Spring Boot. There also should be the possibility to inject them with JNDI as with WAR file. What is the most elegant way achieve it?

0

There are 0 best solutions below