4
votes

I am using spring-batch-admin-manager-1.2.2.RELEASE along with spring-batch 2.2.3.RELEASE in my project. I am trying to use the spring batch admin console along with my webapp to monitor the batch jobs. When I deploy my web-application on tomcat, I get the following application initialization error. I have browsed through this JIRA ticket https://jira.springsource.org/browse/BATCHADM-151 which mentions that this bug has been fixed to support Spring Batch 2.2.0 but the version of spring-batch-admin-manager released for this fix says it is 1.3.0. I couldn't find 1.3.0 anywhere on maven repo and I am not able to deploy my application along with Spring Batch Admin. Am I missing something here?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobService': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.batch.admin.service.JdbcSearchableJobInstanceDao.setJdbcTemplate(Lorg/springframework/jdbc/core/simple/SimpleJdbcOperations;)V
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
... 86 more
Caused by: java.lang.NoSuchMethodError: org.springframework.batch.admin.service.JdbcSearchableJobInstanceDao.setJdbcTemplate(Lorg/springframework/jdbc/core/simple/SimpleJdbcOperations;)V
at org.springframework.batch.admin.service.SimpleJobServiceFactoryBean.createJobInstanceDao(SimpleJobServiceFactoryBean.java:195)
at org.springframework.batch.admin.service.SimpleJobServiceFactoryBean.getObject(SimpleJobServiceFactoryBean.java:255)
at org.springframework.batch.admin.service.SimpleJobServiceFactoryBean.getObject(SimpleJobServiceFactoryBean.java:54)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 91 more

Here is my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>rcg-webapp</display-name>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

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

<!-- Spring Batch Admin Configuration -->

<env-entry>
    <env-entry-name>ENVIRONMENT</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>mysql</env-entry-value>
</env-entry>

<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,classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value> -->
        <param-value>classpath:register-spring-admin-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
</web-app>

Here is the contents of the register-spring-admin-servlet.xml file under src.main.resources folder:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<import resource="classpath*:/META-INF/spring/batch/servlet/resources/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/manager/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/override/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/bootstrap/**/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/override/**/*.xml" />

<!-- Override the standard location for spring batch admin resources -->
<bean id="resourceService" class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/batch" />
</bean>

<bean id="parameterUnpackerFilter" class="org.springframework.batch.admin.web.filter.ParameterUnpackerFilter">
    <property name="prefix" value="unpack_"/>
    <property name="putEmptyParamsInPath" value="true"/>
</bean>

</beans>

Here is my application-context.xml under src.main.resources folder:

<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
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-3.0.xsd">

<bean id="resourceService"
        class="org.springframework.batch.admin.web.resources.DefaultResourceService">
    <property name="servletPath" value="/admin-console" />
</bean>

 <!-- stored job-meta in database -->
<bean id="jobRepository"
    class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseType" value="mysql" />
</bean>

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

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

Here is the contents of the datasource.xml file under src.main.resources/META-INF/spring/batch/override folder:

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

<!-- connect to MySQL database -->
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
     <property name="driverClassName" value="${batch.jdbc.driver}" />
    <property name="url" value="${batch.jdbc.url}" />
    <property name="username" value="${batch.jdbc.user}" />
    <property name="password" value="${batch.jdbc.password}" />
</bean>

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

<jdbc:initialize-database data-source="dataSource" enabled="${batch.data.source.init}" ignore-failures="DROPS">
    <jdbc:script location="${batch.drop.script}"/>
    <jdbc:script location="${batch.schema.script}"/>
    <jdbc:script location="${batch.business.schema.script}"/>
</jdbc:initialize-database>
</beans>
1

1 Answers

3
votes

I also had a difficult time setting up a spring-batch-admin project, as there is not much guidance to find on the net. Finally I found this sample project, which is a good starting point.

If you are using STS you can access it via: File -> New -> Spring project -> Batch -> Simple Batch Admin Webapp

EDIT: As for the spring-batch-admin-manager 1.3.0 I dont't see a final release out there as well. But you could give a try to the latest milestone, which seems to be stable enough to be included in the afromentioned sample project.

Put this in your pom.xml

<dependency>
  <groupId>org.springframework.batch</groupId>
  <artifactId>spring-batch-admin-manager</artifactId>
  <version>1.3.0.M1</version>
</dependency>

<repository>
  <id>spring-milestones</id>
  <url>http://repo.springsource.org/libs-milestone/</url>
</repository>

Good luck!