Thursday, July 19, 2007

setting datasource lookup from tomcat JNDI using spring

1. -JNDI configuration is as below: 1. Shutdown liferay/tomcat 2. Modify applicationContext-hibernate.xml as below : Replace - <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="jdbc/dmpPubPool" /> <property name="resourceRef" value="true" /> </bean> Instead of - <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="url"><value>${hibernate.connection.url}</value></property> <property name="driverClassName"><value>${hibernate.connection.driver_class}</value></property> <property name="username"><value>${hibernate.connection.username}</value></property> <property name="password"><value>${hibernate.connection.password}</value></property> </bean> Modify the JNDI path jdbc/dmpPubPool suitable for CMS. 3. Add the context.xml(attached) into /META-INF/ folder of CMS webapp . Modify the JNDI path jdbc/dmpPubPool suitable for CMS. This file has <Context reloadable="true"> <ResourceLink name="jdbc/dmpPubPool" type="javax.sql.DataSource" global="jdbc/dmpPubPool"/> <ResourceLink name="jdbc/adServerPool" type="javax.sql.DataSource" global="jdbc/adServerPool"/> </Context> 4. Update the server.xml of your liferay available under <liferay>/conf as below <GlobalNamingResources> <Resource name="jdbc/dmpPubPool" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@172.20.41.40:1521:xyz" removeAbandoned="true" maxActive="75" maxIdle="30" maxWait="-1" username="****" password="***" validationQuery="select 1 from dual" /> …..> Copy ojdbc.jar available under cms/web-inf/lib into <LRay>\common\lib\ext Modify the url and other settings as per your application. 5. Remove all the org.springframework.jdbc.datasource.DriverManagerDataSource and use javax.sql.DataSource; 6. Deploy CMS app and Startup liferay 7. Test if the db connection is fine. The ant script might not copy the META-INF/context.xml file. Modify the ant script for CMS with <target name="build" depends="compile"> <war> ….. <!--Copy the META-inf library files --> <zipfileset dir="${srcdir}/webapp/META-INF" prefix="META-INF/" /> …. ……

1 comment:

Anonymous said...

Thanks a lot for this post.

Spring throwing exception like "Datasource not bound to context"

I tried adding resource-ref in web.xml. it created some other issue.

Adding context.xml in META-INF folder,solved my problem.