Use a JDBC datasource from WebLogic’s JNDI
Case
Your application is connected to a database. The configuration of the DB connexion is set in a Spring file. You would like the connexion to be set in WebLogic, so that no URL/login/password lays in your source code.
Steps
WebLogic
Create a new data source:
- go the WebLogic console >
- JDBC >
- DataSource >
- New >
- set the name, JNDI name (eg:
database.jndi.name
), DB type (Oracle, Sybase, …) >- Next >
- Select the driver >
- Next >
- Select the targeted server(s)
- Next >
- Select the driver >
- Next >
- set the name, JNDI name (eg:
- New >
- DataSource >
- JDBC >
This will
- create a new file
<yourDomain>/config/jdbc/<datasourceName>-XXXX-jdbc.xml
. - add a
<jdbc-system-resource>
block in<yourDomain>/config/config.xml
Spring
Replace the block:
[xml]<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>[/xml]
with:
[xml]<jee:jndi-lookup id="dataSource" jndi-name="${database.jndi.name}" />[/xml]