Connecting to JNDI Data SourcesConnecting to JNDI Data Sourceshttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1180329602024-03-29T09:14:19Z2024-03-29T09:14:19ZRE: Connecting to JNDI Data SourcesPankaj Kumarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180425102019-12-10T16:11:07Z2019-12-10T16:11:07ZOk..Thanks...I was able to get the Datasource connection through the way we get in J2EE application.<br />InitialContext ctx = new InitialContext();Pankaj Kumar2019-12-10T16:11:07ZRE: Connecting to JNDI Data SourcesDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180413142019-12-10T13:20:49Z2019-12-10T13:20:49ZYou can't use the spring example because it will not properly set the class loader.David H Nebinger2019-12-10T13:20:49ZRE: Connecting to JNDI Data SourcesPankaj Kumarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180361322019-12-10T05:03:10Z2019-12-10T05:03:10ZThanks David for response.<br />In ext.spring file i have added below property <bean id="bean1" class="org.springframework.jndi.JndiObjectFactoryBean"><br /> <property name="jndiName" value="java:comp/env/jdbc/db1" /><br /> <br /> </bean><br /> <br /> <bean id="customDBDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true"><br /> <property name="targetDataSource"><br /> <ref bean="bean1" /><br /> </property>and while starting the module i am getting below error<br /> Invocation of init method failed; nested except<br />ion is javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lan<br />g.ClassNotFoundException: Unable to load class org.apache.naming.java.javaURLContextFactory]<br /> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)Pankaj Kumar2019-12-10T05:03:10ZRE: Connecting to JNDI Data SourcesDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180353352019-12-09T21:11:41Z2019-12-09T21:11:41ZThe only caveat is that you need to set the class loader to the portal's class loader before you invoke the JNDI lookup.<br /><br />Otherwise the JNDI lookup is exactly the same as you would do it in any other application.David H Nebinger2019-12-09T21:11:41ZConnecting to JNDI Data SourcesPankaj Kumarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=118032959