0

I have a spring mvc webapp with spring batch built into it. I am having some issues getting my spring batch jobs to be launchable in the spring batch admin console. This is what I see when I go to the jobs page...

enter image description here

All of my jobs are coming up as launchable=false. I was wondering how I can fix this. I read some documentation about why this would be so and it said that I need to use a AutomaticJobRegistrar.

I tried this but it didn't change anything. I've put my spring batch job configuration below. Would appreciate it someone could tell me what is missing.

thanks

<beans profile="pre,prod">

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

    <bean id="jobRepository"
        class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
        parent="abstractCustDbJdbcDao">     
        <property name="transactionManager" ref="custDbTransactionManager" />
        <property name="databaseType" value="db2" />
        <property name="tablePrefix" value="REPMAN.BATCH_" />
    </bean>

    <bean id="jobExplorer"
            class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean" 
            parent="abstractCustDbJdbcDao" />                   

    <bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
        <property name="jobRegistry" ref="jobRegistry" />
    </bean>

    <bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
        <property name="applicationContextFactories">
            <bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
                <property name="resources" value="classpath*:/META-INF/spring/jobs/*.xml" />
            </bean>
        </property>
        <property name="jobLoader">
            <bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
                <property name="jobRegistry" ref="jobRegistry" />
            </bean>
        </property>
    </bean>

    <bean id="jobRegistry"
        class="org.springframework.batch.core.configuration.support.MapJobRegistry" />                          

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails">
           <list>
              <ref bean="dailyTranCountJobDetail" />
              <ref bean="bulletinBarMsgUpdateJobDetail" />
              <ref bean="updateLovCacheJobDetail" />
           </list>
        </property>
        <property name="triggers">
           <list>
              <ref bean="dailyTranCountCronTrigger" />
              <ref bean="bulletinBarMsgUpdateCronTrigger" />
              <ref bean="updateLovCacheCronTrigger" />
           </list>
        </property>
    </bean>

    <!-- scheduling properties -->
    <util:properties id="batchProps" location="classpath:batch.properties" />
    <context:property-placeholder properties-ref="batchProps" />        

    <!-- triggers -->
    <bean id="dailyTranCountCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="dailyTranCountJobDetail" />
        <property name="cronExpression" value="#{batchProps['cron.dailyTranCounts']}" />
    </bean>

    <bean id="bulletinBarMsgUpdateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="bulletinBarMsgUpdateJobDetail" />
        <property name="cronExpression" value="#{batchProps['cron.bulletinBarUpdateMsg']}" />
    </bean>     

    <bean id="updateLovCacheCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="updateLovCacheJobDetail" />
        <property name="cronExpression" value="#{batchProps['cron.updateLovCache']}" />
    </bean>         

    <!-- job detail -->
    <bean id="dailyTranCountJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="job-daily-tran-counts" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
            </map>
        </property>
    </bean> 

    <bean id="bulletinBarMsgUpdateJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="job-bulletin-bar-msg-update" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
            </map>
        </property>
    </bean> 

    <bean id="updateLovCacheJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="job-update-lov-cache" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
            </map>
        </property>
    </bean>                 
</beans>            

Richie
  • 4,989
  • 24
  • 90
  • 177

1 Answers1

2

There are a few things this could be:

  1. Where is the XML file you reference above located? It needs to be the META-INF/spring/batch/jobs directory in your WAR file (that's where Spring Batch Admin will look).
  2. Don't configure common components in your XML file. That includes the jobLauncher, jobRepository, jobExplorer, jobLoader, or jobRegistry. That being said, I don't see an actual job defined in your XML file. The XML file needs one of those ;)

You can read more about adding your own job definitions to Spring Batch Admin: http://docs.spring.io/spring-batch-admin/reference/jobs.html#Add_your_Own_Jobs_For_Launching_in_the_UI

Michael Minella
  • 20,843
  • 4
  • 55
  • 67
  • So as you can see in my config The jobs were not defined in the directory you specified. They were in...classpath*:/META-INF/spring/jobs/*.xml. I'll try the dir you specified now and see if it fixes it. – Richie May 20 '14 at 03:01
  • ok so I have now changed the location of the batch job xml files to classpath*:/META-INF/spring/batch/jobs/*.xml. But still the admin says they are not launchable. I am not sure what you mean by don't figure common components? Could you explain more what you mean by common? – Richie May 20 '14 at 04:25
  • The list of beans that I mentioned are already configured in a parent context in Spring Batch Admin. Are you using the sample application to build your app or have you taken another path? – Michael Minella May 20 '14 at 14:13
  • I am using the sample application spring batch admin console. The configuration I provided is the configuration for the application with the batch jobs – Richie May 21 '14 at 12:20
  • Besides the Quartz related beans, I see nothing that should be in that file. It's all provided for you in the Spring Batch Admin's parent context so they can be shared by all jobs. – Michael Minella May 21 '14 at 14:27
  • sorry i think you have misunderstood. The configuration I provided above is for my custom webapp (the one with the spring batch jobs). In addition to my custom web application I also have deployed the spring batch admin sample web application. My intention of doing this is that using the admin console I will be able to see the spring batch jobs run in my custom web application. I can see the jobs okay but I cannot launch them? Does this clarify things? (thanks for your help) – Richie May 22 '14 at 09:57
  • Ah…yes. That clarifies things a lot. That isn't supported with Spring Batch Admin. SBA only supports launching local jobs (jobs deployed within the Spring Batch Admin application). – Michael Minella May 22 '14 at 14:35
  • crap. that's a shame. I will have to embed spring batch admin in my app – Richie May 22 '14 at 22:01
  • Well, do keep in mind that embedding admin in your app isn't that bad. You can drop in the jar files which will expose the REST endpoints without pulling any of the UI components in. – Michael Minella May 22 '14 at 22:33
  • I've found a link http://stackoverflow.com/questions/6438570/integrating-spring-batch-admin-into-an-existing-application which has someone who thinks they have easily been able to integrate the admin console into their app. I might copy what they have done. I am a bit lost though on what they actually have achieved using the configuration that they have. Ie. By adding another dispatcher servlet to spring batch admin console in my web app what will I end up with? – Richie May 23 '14 at 07:29