Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Spring applications


Configure access to a Spring application data source

We can use WAS to manage access to a data source for a Spring application.

For a Spring application to access a data source, such as a JDBC data source, the application must use a resource provider that is managed by the WAS. For more information about Spring applications and the Spring Framework see the following topics:


Procedure

  1. During development, configure the WAR module with a resource reference. For example:
    <resource-ref>
    <res-ref-name>jdbc/springdbres-ref-name>jdbc/springdb>
    <res-type>javax.sql.DataSourceres-type>javax.sql.DataSource>
    <res-auth>Containerres-auth>Container>
    <res-sharing-scope>Shareableres-sharing-scope>Shareable>
    </resource-ref> 

  2. For EJB JAR files, declare the same resource reference in each EJB that needs to access the data source. Use one of the following steps:

    • Declare a data source proxy bean. In the Spring application configuration, declare a proxy bean that references a resource provider that the application server manages. Set the value of the jndiName property to java:comp/env/ followed by the value of res-ref-name property that you declared in the resource reference. For example:
      <bean id="wasDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/springdb"/>
      <property name="lookupOnStartup" value="false"/>
      <property name="cache" value="true"/>
      <property name="proxyInterface" value="javax.sql.DataSource"/>
      </bean>
      
    • Alternatively, for Spring Framework v2.5 or later, use the <j2ee:jndi-lookup/> approach. Set the value of the jndi-name property to the value of the res-ref-name property that you declared in the resource reference, and the value of the resource-ref property to true. For example:
      <jee:jndi-lookup id=" wasDataSource "
          jndi-name="jdbc/springdb"
          cache="true"
          resource-ref="true"
          lookup-on-startup="false"
          proxy-interface="javax.sql.DataSource"/> 

    The Spring application can then use the data source proxy bean as appropriate.

  3. When the application is deployed to an application server, configure a resource provider and resource data source that the Spring application resource reference can use.


Results

The resource reference that is declared in the deployment descriptor of the module will be bound to the configured data source of the application server during deployment.
Spring Framework
Data access and the Spring Framework
Spring source community
Spring Community Downloads
SCA Spring Component Implementation 1.0.0

+

Search Tips   |   Advanced Search