Search
Calendar
November 2017
S M T W T F S
« Sep    
 1234
567891011
12131415161718
19202122232425
2627282930  
Your widget title
Archives

PostHeaderIcon 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)

This will

  1. create a new file <yourDomain>/config/jdbc/<datasourceName>-XXXX-jdbc.xml.
  2. add a <jdbc-system-resource> block in <yourDomain>/config/config.xml

Spring

Replace the block:

<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>

with:

<jee:jndi-lookup id="dataSource" jndi-name="${database.jndi.name}" />

Leave a Reply