Java – How to use JNDI DataSource provided by WebLogic in Spring

datasourcejavajndispringweblogic

It is said in Spring javadoc article about DriverManagerDataSource class, that this class is very simple and that it is recommended

to use a JNDI DataSource provided by the container. Such a DataSource can be exposed as a DataSource bean in a Spring ApplicationContext via JndiObjectFactoryBean

The question is: how to accomplish this?

For example if I wish to have DataSource bean to access my custo oracle database, what I require then? What to write in context configuration etc?

Best Answer

To access a JNDI data source you do something like:

<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDatabase"/>
</bean>

or look et the spring 'jee' schema.

The details of the database connection are configured in WebLogic, the application accesses the database through the jndi name.

Related Topic