Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Connecting to JNDI Data Sources
Hi All,
I am using Liferay dxp 7.2.Can any body tell me how we can connect to external database using JNDI Data Sources.
Thanks,Pankaj Semwal
I am using Liferay dxp 7.2.Can any body tell me how we can connect to external database using JNDI Data Sources.
Thanks,Pankaj Semwal
The only caveat is that you need to set the class loader to the portal's class loader before you invoke the JNDI lookup.
Otherwise the JNDI lookup is exactly the same as you would do it in any other application.
Otherwise the JNDI lookup is exactly the same as you would do it in any other application.
Thanks David for response.
In ext.spring file i have added below property <bean id="bean1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/db1" />
</bean>
<bean id="customDBDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
<property name="targetDataSource">
<ref bean="bean1" />
</property>and while starting the module i am getting below error
Invocation of init method failed; nested except
ion is javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lan
g.ClassNotFoundException: Unable to load class org.apache.naming.java.javaURLContextFactory]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
In ext.spring file i have added below property <bean id="bean1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/db1" />
</bean>
<bean id="customDBDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
<property name="targetDataSource">
<ref bean="bean1" />
</property>and while starting the module i am getting below error
Invocation of init method failed; nested except
ion is javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lan
g.ClassNotFoundException: Unable to load class org.apache.naming.java.javaURLContextFactory]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
You can't use the spring example because it will not properly set the class loader.
Ok..Thanks...I was able to get the Datasource connection through the way we get in J2EE application.
InitialContext ctx = new InitialContext();
InitialContext ctx = new InitialContext();
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™