In this post I want to share liferay DB configuration using JNDI instead of portal-ext.properties.
For JDBC connection we use portal-ext.properties.
If your custom service builder portlet is pointing to another database then we can use JNDI to configure that database.
<!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="jdbc/CustomDBPoolShared" auth="Container" type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@YOUR_SERVER:1521:YOUR_SERVICE" username="root" password="root" maxActive="20" maxIdle="5" maxWait="10000" /> ...... </GlobalNamingResources>
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> <ResourceLink name="jdbc/CustomDBPoolShared" global="jdbc/CustomDBPoolShared" type="javax.sql.DataSource"/> .... </Context>
<bean id="customDBDataSourceTarget" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true"> <property name="jndiName"> <value>java:/comp/env/jdbc/CustomDBPoolShared</value> </property> </bean> <bean id="customDBDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true"> <property name="targetDataSource"> <ref bean="customDBDataSourceTarget" /> </property> </bean>
Thats IT!
So this way we can configure liferay database configuration using JNDI.


