我是Batch Job的新手。当我尝试在Tomcat中托管批处理作业时,出现以下异常:
如果我尝试以独立方式执行批处理作业,它将在数据库批处理表中工作并进行更新。
这可能是个小问题,但无法弄清楚。我在网上搜索。但是无法获得解决方案。
配置文件:
applicationContext.xml:
<context:annotation-config />
<context:component-scan base-package="com.sample.feed" />
<import resource="classpath:META-INF/data-source-context.xml" />
<bean id="simpleStep"
class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler" />
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
<bean id="jobParameterIncrementer"
class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<!-- <property name="taskExecutor" ref="jobLauncherTaskExecutor" /> -->
</bean>
<batch:job id="SAMPLEAppFeedLoader" job-repository="jobRepository"
incrementer="jobParameterIncrementer" xmlns="http://www.springframework.org/schema/batch">
<batch:step id="FeedDBProcessing" parent="simpleStep">
<!-- <batch:tasklet task-executor="taskExecutor"> -->
<batch:tasklet>
<!-- throttle-limit="10"> -->
<chunk reader="SAMPLEAppReader" writer="DBBatchWriter"
processor="SAMPLEAppProcessor" commit-interval="1">
</chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="SAMPLEAppLoader" class="com.sample.feed.model.SAMPLEAppLoader" />
<bean id="itemReader" class="com.sample.feed.reader.SynchronisedReader"
scope="step">
<property name="delegate" ref="SAMPLEAppReader" />
</bean>
<bean id="SAMPLEAppReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
<property name="dataSource" ref="dataSource" />
<property name="saveState" value="false" />
<property name="sql">
<value> <![CDATA[ select e.MONT_DATA_VAL_ID, e.SUBR_NBR, e.RES_BLOB.getClobVal()
clobvalue from MON_DATA_VAL e where e.MONT_DATA_VAL_ID >= 588369 AND e.MONT_DATA_VAL_ID
<= 588389]]>
</value>
</property>
<property name="rowMapper">
<bean class="com.sample.feed.mapper.SAMPLEAppMapper" />
</property>
<property name="verifyCursorPosition">
<value>false</value>
</property>
</bean>
<bean id="SAMPLEAppProcessor" class="com.sample.feed.processor.SAMPLEAppProcessor">
<property name="filePath" value="D:\\input\\SAMPLEapp\\" />
</bean>
<bean id="SAMPLEAppWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
update MON_DATA_VAL set path = :filePathValue where MONT_DATA_VAL_ID = :mont_data_val_id
]]>
</value>
</property>
<property name="itemSqlParameterSourceProvider">
<bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
</bean>
<bean id="DBBatchWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="assertUpdates" value="true" />
<property name="itemPreparedStatementSetter">
<bean class="com.sample.feed.mapper.PSSetter" />
</property>
<property name="sql">
<value>
<![CDATA[
update MON_DATA_VAL set path = ? where MONT_DATA_VAL_ID = ?
]]>
</value>
</property>
</bean>
<bean id="SAMPLEFeedWriter" class="com.sample.feed.writer.SAMPLEAPPWriter">
<property name="SAMPLEMessageDao" ref="SAMPLEMessageDao" />
</bean>
<bean id="SAMPLEMessageDao" class="com.sample.feed.daoImpl.SAMPLEMessageDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="SAMPLEUpdateQuery"
value="update MON_DATA_VAL set path = ? where MONT_DATA_VAL_ID = ?" />
<property name="SAMPLEAppLoader" ref="SAMPLEAppLoader" />
</bean>
data-source-context.xml:
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="dataSource" ref="dataSource" />
<property name="tablePrefix" value="BATCH_" />
<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
</bean>
<context:annotation-config />
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="URL" value="${batch.jdbc.url}"></property>
<property name="password" value="${batch.jdbc.password}"></property>
<property name="user" value="${batch.jdbc.user}"></property>
</bean>
<bean id="namedJdbcTemplate"
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
注意:这可能是多线程的原因吗?在这里,我删除了多线程并进行了检查。仍然例外。