3

We are facing following exception while executing spring batch job from command line. Spring Batch Version - 3.0.2.RELEASE Spring Version - 4.0.0.RELEASE xStream version - 1.4.7 Data Base - mysql (I am connecting to new DB schema.) While executing a job using following command, I am getting below exception...

    java %JAVA_OPTS% org.springframework.batch.core.launch.support.CommandLineJobRunner config/spring-config.xml partitionJdbcJob

    Exception
    ----------

    INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
    Feb 20, 2015 3:22:28 PM org.springframework.batch.core.launch.support.SimpleJobLauncher afterPropertiesSet
    INFO: No TaskExecutor has been set, defaulting to synchronous executor.
    Feb 20, 2015 3:22:29 PM org.springframework.batch.core.launch.support.SimpleJobLauncher run
    INFO: Job: [FlowJob: [name=partitionJdbcJob]] launched with the following parameters: [{}]
    Feb 20, 2015 3:22:29 PM org.springframework.batch.core.job.AbstractJob execute

    SEVERE: Encountered fatal error executing job
    org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
            at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:140)
            at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
            at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
            at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
            at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:362)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:590)
    Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=partitionJdbcJob at state=partitionJdbcJob.step with exception
            at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:174)
            at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
            at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
            ... 6 more
    Caused by: com.thoughtworks.xstream.converters.ConversionException: Cannot construct java.util.Map$Entry : java.util.Map$Entry : Cannot construct java.util.Map$
    Entry : java.util.Map$Entry

    ---- Debugging information ----
    message             : Cannot construct java.util.Map$Entry : java.util.Map$Entry
    cause-exception     : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
    cause-message       : Cannot construct java.util.Map$Entry : java.util.Map$Entry
    class               : java.util.Map$Entry
    required-type       : java.util.Map$Entry
    converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
    path                : /map/map/entry
    line number         : -1
    class[1]            : java.util.HashMap
    converter-type[1]   : com.thoughtworks.xstream.converters.collections.MapConverter
    version             : 1.4.7
    -------------------------------
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
            at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
            at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71)
            at com.thoughtworks.xstream.converters.collections.MapConverter.putCurrentEntryIntoMap(MapConverter.java:106)
            at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:98)
            at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:92)
            at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:87)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
            at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
            at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
            at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185)
            at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1169)
            at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1040)
            at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1031)
            at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.deserialize(XStreamExecutionContextStringSerializer.java:112)
            at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.deserialize(XStreamExecutionContextStringSerializer.java:45)
            at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:322)
            at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:309)
            at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
            at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)
            at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:706)
            at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:642)
            at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:693)
            at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:725)
            at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:735)
            at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:790)
            at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.getExecutionContext(JdbcExecutionContextDao.java:127)
            at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastStepExecution(SimpleJobRepository.java:238)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
            at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
            at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
            at $Proxy7.getLastStepExecution(Unknown Source)
            at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:115)
            at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
            at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
            at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165)
            ... 8 more
    Caused by: com.thoughtworks.xstream.converters.reflection.ObjectAccessException: Cannot construct java.util.Map$Entry : java.util.Map$Entry
            at com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider.newInstance(SunLimitedUnsafeReflectionProvider.java:80)
            at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:553)
            at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:256)
            at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
            ... 57 more
    Caused by: java.lang.InstantiationException: java.util.Map$Entry
            at sun.misc.Unsafe.allocateInstance(Native Method)
            at com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider.newInstance(SunLimitedUnsafeReflectionProvider.java:76)
            ... 60 more
Spring Config
----------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd
                            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
                            http://www.springframework.org/schema/task 
                            http://www.springframework.org/schema/task/spring-task-3.2.xsd">

    <context:annotation-config /> 

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/newspringbatch?useServerPrepStmts=false&amp;rewriteBatchedStatements=true" />
        <property name="username" value="uid" />
        <property name="password" value="pwd" />
    </bean>

    <bean id="transactionManager"
        class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg ref="pooledDS" />
    </bean>

    <!-- DB Pooling -->
    <bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
        <property name="minEvictableIdleTimeMillis"><value>300000</value></property>
        <property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
    </bean>

    <bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
        <constructor-arg><ref bean="dataSource"/></constructor-arg>
    </bean>

    <bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
        <constructor-arg index="0"><ref bean="dsConnectionFactory"/></constructor-arg>
        <constructor-arg index="1"><ref bean="pool"/></constructor-arg>
        <constructor-arg index="2"><null/></constructor-arg>
        <constructor-arg index="3"><null/></constructor-arg>
        <constructor-arg index="4"><value>false</value></constructor-arg>
        <constructor-arg index="5"><value>true</value></constructor-arg>
    </bean>

    <bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory">
        <constructor-arg><ref bean="pool"/></constructor-arg>
    </bean>

    <!-- stored job-meta in database -->
    <bean id="batchDefaultSerializer" class="org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer" />


    <bean id="jobRepository"
        class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="pooledDS" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseType" value="mysql" />  

    </bean>

    <bean id="jobLauncher"
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>

    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"></bean>

    <bean id="userUnmarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"></bean>

    <job id="partitionJdbcJob" restartable="true" xmlns="http://www.springframework.org/schema/batch">  
        <step id="step" >
            <partition step="createFiles" partitioner="partitioner">
                <handler grid-size="50" task-executor="taskExecutor" />
            </partition>
        </step>
        <listeners>
            <listener ref="jobDurationListener" />
        </listeners>
    </job>

    <step id="createFiles" xmlns="http://www.springframework.org/schema/batch">
        <tasklet>
            <chunk reader="pagingItemReader" processor="filesItemProcessor"
                writer="filesItemWriter" commit-interval="200" />
        </tasklet>
    </step>

    <!-- PagingItemReader will be used for big records only -->
    <bean id="pagingItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader"
        scope="step" autowire-candidate="false">
        <property name="dataSource" ref="pooledDS" />
        <property name="rowMapper" ref="reconRowMapper" />
        <!-- Query Provider -->
        <property name="queryProvider">
            <bean
                class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
                <property name="dataSource" ref="pooledDS" />
                <property name="fromClause" value="from sample" />
                <property name="selectClause" value="id,name" />
                <property name="sortKey" value="id" />

            </bean>
        </property>

        <!-- Inject via the ExecutionContext in partitioner -->
        <property name="parameterValues">
            <map>
                <entry key="minId" value="#{stepExecutionContext[minValue]}" />
                <entry key="maxId" value="#{stepExecutionContext[maxValue]}" />
            </map>
        </property>
    </bean>

    <bean id="filesItemProcessor" class="com.batch.job.ResultProcessor" />

    <bean id="filesItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter"
        scope="step">
        <property name="resource" value="#{stepExecutionContext[outputFile]}" />
        <property name="shouldDeleteIfExists" value="true" />
        <property name="lineAggregator">
            <bean
                class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                <property name="delimiter" value="," />
                <property name="fieldExtractor">
                    <bean
                        class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                        <property name="names" value="id,name" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>


    Feb 20, 2015 3:22:29 PM org.springframework.batch.core.launch.support.SimpleJobLauncher run
    INFO: Job: [FlowJob: [name=partitionJdbcJob]] completed with the following parameters: [{}] and the following status: [FAILED]
    Feb 20, 2015 3:22:29 PM org.springframework.context.support.ClassPathXmlApplicationContext doClose
    INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext
    @d37d44: startup date [Fri Feb 20 15:22:27 IST 2015]; root of context hierarchy
sandip desale
  • 61
  • 2
  • 3
  • Can you provide what was in your `ExecutionContext` at the time of the failure? – Michael Minella Feb 20 '15 at 16:06
  • Hi Michael,thanks for reply. My apologies for replying late. Can you let me know how to get the execution context. I am using a partitionar using which I am injecting 3 params to it. and finally it is kept in a map. When I am executing it through eclipse then it works fine but through command prompt with the help of batch file it fails. In eclipse, I am using a schedular which inturn triggers a job where as in command prompt there is no schedular in plance. – sandip desale Feb 25 '15 at 05:03
  • 1
    I am able to resolve it by using the jettison-1.1.jar instead of jettison-1.3.1.jar. http://stackoverflow.com/questions/22306080/spring-batch-jdbcexecutioncontextdao-java-util-mapentry-deserializer-issue-xs – sandip desale Feb 25 '15 at 07:30
  • thanks @sandipdesale!! – OhadR Oct 29 '15 at 06:02

3 Answers3

1

Had same issue when running Spring Batch Job. At:

Set<JobExecution> runningJobExecutions = jobExplorer.findRunningJobExecutions(jobName);

Solved by using jettison 1.1 instead of 1.3.2

李骏豪
  • 151
  • 1
  • 2
0

While changing the version of the Jettison jar got rid of the error for me as well, that didn't solve the underlying problem.

In my case the ultimate cause was having two steps with the same name. Once I fixed that, the reported exception went away.

cneff
  • 388
  • 6
  • 15
0

Error message though confusing points to duplicate jobs/steps. Creating unique jobs/steps helped fix the issue for me. No other change needed.

Ashok
  • 211
  • 2
  • 4