Spring batch job repository configuration for WebSphere and Oracle
Published: Dec 02, 2015
This article describes an issue with the default Spring Batch Job Repository configuration when deployed on a WebSphere application server backed by an Oracle database.
The following exception may occur:
org.springframework.dao.DataAccessResourceFailureException: Could not create Oracle LOB
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Couldn't initialize OracleLobHandler because Oracle driver classes are not available. Note that OracleLobHandler requires Oracle JDBC driver 9i or higher!; nested exception is java.lang.ClassNotFoundException: oracle.sql.BLOB
Caused by: java.lang.ClassNotFoundException: oracle.sql.BLOB
This issue is documented on the IBM support website.
Configuration
The proper solution is to configure the LOB handler dependency of the Job Repository and inject an OracleLobHandler bean.
For WebSphere support, the lobHandler
bean must be instantiated with a compatible nativeJdbcExtractor
provided by WebSphere.
The following snippet shows the Job Repository configuration details:
<batch:job-repository id="jobRepository"
data-source="dataSource"
transaction-manager="transactionManager"
lob-handler="lobHandler" />
<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
</bean>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" />
Data source configuration
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/DS_NAME" />
<property name="lookupOnStartup" value="true" />
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
Transaction manager configuration
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" primary="true">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>