Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JNDI DataSource provided by WebLogic 12.2.1 in Spring?

I created a JNDI connection with the following Values:

i selected Generic Data Source option

Name: jdbc/sampleDataSource

JNDI Name: jdbc/sampleDataSource

Spring Config File:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/sampleDataSource" />

I'm getting below error.

Error An error occurred during activation of changes, please see the log for details.
Error javax.naming.NameNotFoundException: While trying to lookup 'jdbc.sampleDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/sampleDataSource'
Error While trying to lookup 'jdbc.sampleDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/sampleDataSource' 

I was unable to resolve it. How do i configure in Spring 4. Any addition jar file is required. Please help on this.

like image 586
Rajesh Narravula Avatar asked Jan 25 '16 11:01

Rajesh Narravula


People also ask

What is the use of JNDI in Weblogic?

JNDI provides a common-denominator interface to many existing naming services, such as LDAP (Lightweight Directory Access Protocol) and DNS (Domain Name System). These naming services maintain a set of bindings, which relate names to objects and provide the ability to look up objects by name.

Is JNDI used in spring?

JPA Configuration – Model, DAO and Service. With this, you have everything you need in order to use your JNDI datasource in your Spring application.


1 Answers

Sometimes this happens when you forget to Target your defined datasource to a specific server. You can find it in Weblogic's administration server :

enter image description here

then in the Targets tab:

enter image description here

you should select the target.

If that wasn't the problem, you may try the way of getting your datasource in the applicationContext.xml:

<bean id="dataSource" name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/mcdsDS"/>
    <property name="resourceRef" value="true"/>
</bean>

And use the dataSource reference wherever you need a datasource.

Hope this would be helpful.

like image 186
STaefi Avatar answered Nov 13 '22 05:11

STaefi