Announcement Announcement Module
Collapse
No announcement yet.
configuration of job repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • configuration of job repository

    Hi,

    I am newby to Spring batch nad I am trying to configure jobRepository to run on postgreSQL.
    my xml contains the following:


    <?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schem...-batch-2.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- 1) USE ANNOTATIONS TO CONFIGURE SPRING BEANS -->
    <context:component-scan base-package="com.batch" />
    <!-- class="org.apache.commons.dbcp.BasicDataSource" -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource"
    destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbcostgresql://<HOST>:5432/postgres" />
    <property name="username" value="<USR>" />
    <property name="password" value="<PWD>" />
    </bean>

    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSou rceTransactionManager"
    lazy-init="true">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="jobRepository"
    class="org.springframework.batch.core.repository.s upport.JobRepositoryFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseType" value="postgres" />
    <property name="tablePrefix" value="batch_" />
    </bean>


    <!-- 4) LAUNCH JOBS FROM A REPOSITORY -->
    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    </bean>




    When I try to run the JUnit I get the Exception:
    (The JUnit runs fine with in-memory jobRepository)

    Any ideas what went wrong or what is missing?
    Thanks,
    Aviad.


    java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:203)
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.injectDependencies (DependencyInjectionTestExecutionListener.java:109 )
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.prepareTestInstanc e(DependencyInjectionTestExecutionListener.java:75 )
    at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:255)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:93)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:130)
    at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobRepository' defined in class path resource [com/batch/indications/indi.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:381)
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:84)
    at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:42)
    at org.springframework.test.context.TestContext.loadA pplicationContext(TestContext.java:173)
    at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:199)
    ... 16 more
    Caused by: java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory
    at com.thoughtworks.xstream.io.json.JettisonMappedXml Driver.<init>(JettisonMappedXmlDriver.java:46)
    at org.springframework.batch.core.repository.dao.XStr eamExecutionContextStringSerializer.init(XStreamEx ecutionContextStringSerializer.java:65)
    at org.springframework.batch.core.repository.dao.XStr eamExecutionContextStringSerializer.afterPropertie sSet(XStreamExecutionContextStringSerializer.java: 60)
    at org.springframework.batch.core.repository.dao.Jdbc ExecutionContextDao.afterPropertiesSet(JdbcExecuti onContextDao.java:154)
    at org.springframework.batch.core.repository.support. JobRepositoryFactoryBean.createExecutionContextDao (JobRepositoryFactoryBean.java:176)
    at org.springframework.batch.core.repository.support. AbstractJobRepositoryFactoryBean.getTarget(Abstrac tJobRepositoryFactoryBean.java:140)
    at org.springframework.batch.core.repository.support. AbstractJobRepositoryFactoryBean.initializeProxy(A bstractJobRepositoryFactoryBean.java:129)
    at org.springframework.batch.core.repository.support. AbstractJobRepositoryFactoryBean.afterPropertiesSe t(AbstractJobRepositoryFactoryBean.java:135)
    at org.springframework.batch.core.repository.support. JobRepositoryFactoryBean.afterPropertiesSet(JobRep ositoryFactoryBean.java:130)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1368)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1334)
    ... 32 more
    Caused by: java.lang.ClassNotFoundException: org.codehaus.jettison.mapped.MappedXMLOutputFactor y
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    ... 43 more

  • #2
    You need to add jettison to your classpath (it is used to serialize/deserialize the ExecutionContext in a JDBC JobRepository, but not in memory).

    Please use [code][/code] tags for stack traces and code samples.

    Comment


    • #3
      thanks

      Thank you - I figured it out...

      Off topic - could you pooint me to some code example of how some failed job can be restarted?
      I am trying to do somerthing like:
      JobExecution jex = jobRepository.getLastJobExecution(sJob.getName(), jobParameters);
      if(jex.getStatus()== BatchStatus.FAILED) {
      ...
      JobExecution jexNew = jobRepository.createJobExecution(sJob.getName(), jobParameters);
      ...
      }


      But the relevant job execution is stuck 'STARTING' with START_TIME=null

      What needs to be done to get failed job run again?

      Thanks,

      Aviad

      Comment


      • #4
        trying the code tags...

        Code:
        JobExecution jex = jobRepository.getLastJobExecution(sJob.getName(), jobParameters);
        if(jex.getStatus()== BatchStatus.FAILED) {
        ...
        JobExecution jexNew = jobRepository.createJobExecution(sJob.getName(), jobParameters);
        ...
        }

        Comment

        Working...
        X