Spring Batch Admin - 实例化Bean'workService'时出错

时间:2014-02-21 10:43:49

标签: spring-batch spring-batch-admin

我在我的项目中使用spring-batch-admin-manager-1.2.2.RELEASE以及spring-batch 2.2.3.RELEASE。我正在尝试使用spring批处理管理控制台和我的webapp来监视批处理作业。当我在tomcat上部署我的Web应用程序时,我收到以下应用程序初始化错误。我浏览了这个JIRA票证https://jira.springsource.org/browse/BATCHADM-151,其中提到已修复此错误以支持Spring Batch 2.2.0,但为此修复程序发布的spring-batch-admin-manager版本表示它是1.3.0。我无法在maven repo上找到1.3.0,我无法将我的应用程序与Spring Batch Admin一起部署。我在这里错过了什么吗?

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

这是我的web.xml文件

<?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>

以下是src.main.resources文件夹下的register-spring-admin-servlet.xml文件的内容:

<?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>

这是我在src.main.resources文件夹下的application-context.xml:

<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>

以下是src.main.resources / META-INF / spring / batch / override文件夹下datasource.xml文件的内容:

<?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 个答案:

答案 0 :(得分:3)

我也很难设置一个spring-batch-admin项目,因为在网上找不到太多的指导。 最后我找到了这个sample project,这是一个很好的起点。

如果您使用STS,可以通过以下方式访问它:File -> New -> Spring project -> Batch -> Simple Batch Admin Webapp

编辑:至于spring-batch-admin-manager 1.3.0,我也没看到最终版本。但你可以尝试一下最新的里程碑,它似乎足够稳定,可以包含在上述的示例项目中。

将它放在你的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>
祝你好运!