0

I have a spring batch admin application, where i have job xmls in META-INF/spring/jobs/ folder.

The job initialization fails with below error..

If i change the jobs folder to something say "bootstrap"...the application works..but with jobs not being registered.. Did anyone come across such issues.

My understanding is the each job has a different application context.. But what the exception is saying is I am doing it in 'root' context

Caused by: org.springframework.context.ApplicationContextException: Cannot reinitialize with different application context: current one is [Root WebApplicationContext: startup date [Mon Jul 28 19:08:01 GMT+05:30 2014]; root of context hierarchy], passed-in one is [ResourceXmlApplicationContext:file:/Users/thrinath.d/abc/alliances/alliances/alliances-batch/target/alliances-batch/WEB-INF/classes/META-INF/spring/batch/jobs/alliances-campaign-retry-process.xml]
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:78)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 62 more

Jul 28, 2014 7:08:07 PM org.apache.catalina.core.ApplicationContext log

Sample job xml is included below

<?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:batch="http://www.springframework.org/schema/batch"
   xmlns:task="http://www.springframework.org/schema/task"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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.0.xsd">

<!--Imports-->

<import resource="classpath*:META-INF/spring/batch/alliances-batch-context.xml"/>
<import resource="classpath*:META-INF/spring/batch/global-job-context.xml"/>

<!--Imports Ends-->

<!--Job schedule Beans-->

<task:scheduler id="alliancesCampaignRetryScheduler" pool-size="5"/>

<task:scheduled-tasks scheduler="alliancesCampaignRetryScheduler">
    <task:scheduled ref="alliancesCampaignRetrySchedulingLauncher" method="launch" fixed-delay="1800000"/>
</task:scheduled-tasks>

<bean id="alliancesCampaignRetrySchedulingLauncher"
      class="com.abc.alliances.batch.SynchronousSingletonJobLauncher">
    <constructor-arg name="newJob" ref="alliances-campaign-retry-process" />
    <constructor-arg name="newJobLauncher" ref="jobLauncher"/>
    <constructor-arg name="newJobExplorer" ref="jobExplorer"/>
</bean>

<!--Job schedule Beans End-->

<!--Job Def-->

<batch:job id="alliances-campaign-retry-process" incrementer="incrementer">
    <batch:step id="campaignRetryProcessor" >
        <batch:tasklet ref="alliancesCampaignRetryProcessor"/>
    </batch:step>
    <batch:listeners>
        <batch:listener ref="skipLogger"/>
    </batch:listeners>
</batch:job>

<!--Job Def Ends-->

<!--Processor Defs-->

<bean id="alliancesCampaignRetryProcessor" class="com.abc.alliances.batch.processors.AlliancesPromoRetryProcessor">
    <constructor-arg name="campaignManager" ref="campaignManager" />
    <constructor-arg name="campaignPipelineManager" ref="campaignPipelineManager" />
    <constructor-arg name="campaignRetryQueueDao" ref="campaignRetryQueueDao"/>
    <constructor-arg name="maxRetryCount" value="5"/>
</bean>

<!--Processor Defs Ends-->

web.xml content is attached below

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
        http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
    <filter-name>shallowEtagHeaderFilter</filter-name>
    <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
</filter>

<filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>shallowEtagHeaderFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>Batch Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Batch Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

  • What versions are you using (of Spring Batch Admin and of Spring Batch)? What configuration customizations have you done? – Michael Minella Jul 28 '14 at 14:21
  • 2.1.7.RELEASE 1.2.1.RELEASE META-INF/spring/batch/override has files : admin-web-context.xml, web-context.xml META-INF/spring/batch has my bean context xmls – Thrinath Dosapati Jul 28 '14 at 14:26
  • What about configuration customizations? – Michael Minella Jul 28 '14 at 14:28
  • Can you be more specific..?? I haven't done much changes to the existing batch-admin...other than look and feel of the admin console.. The only problem I see is..If i have my job xmls in a jobs folder, spring batch is reading them differently and the above exception is what i get – Thrinath Dosapati Jul 28 '14 at 15:00
  • I'm looking for *any* additional configuration you've done. What do the jobs look like? What else have you configured (data sources, etc)? While you're correct that each job gets it's own context, it's a child context of the parent context. If I had to guess, you're including something in your jobs that you don't need to but without being able to view the XML, I can't confirm. – Michael Minella Jul 28 '14 at 16:48
  • added the job xml in the Question..jobLauncher and jobExplorer are the default spring batch admin. data source for jobRepository is out of HSQL db which is inmemory – Thrinath Dosapati Jul 28 '14 at 17:44

1 Answers1

0

I commented the following lines which are included in job xml [imported via some other file] and it started working.. can some one gimme the explanation behind

<mvc:annotation-driven/>
<context:annotation-config/>