Spring Batch Admin(2.0.0.M1):创建bean batchMBeanExporter时出错

时间:2016-01-05 15:49:11

标签: spring maven spring-batch spring-batch-admin

我正在尝试从spring boot应用程序运行spring batch admin。

我正在使用迈克尔(@mminella)的this优秀示例。这个应用程序工作正常。

但是,我需要使用maven的类似应用程序;我继续创建一个具有相同文件,作业,配置和依赖项的文件。但我最终还是遇到了异常。

我看到的唯一区别是spring-batch-core的版本。有了maven,它的版本是3.0.6而gradle(迈克尔的应用程序)有3.0.4。

我不确定当我使用maven时会发生什么事情;真的很感谢你的帮助。如果需要任何其他详细信息,请与我们联系。

期待您的投入。

谢谢,

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchMBeanExporter' defined in URL [jar:file:/C:/Users/Admin/.m2/repository/org/springframework/batch/spring-batch-admin-manager/2.0.0.BUILD-SNAPSHOT/spring-batch-admin-manager-2.0.0.BUILD-SNAPSHOT.jar!/META-INF/spring/batch/bootstrap/manager/jmx-context.xml]: Cannot create inner bean 'org.springframework.aop.framework.ProxyFactoryBean#7807ac2c' of type [org.springframework.aop.framework.ProxyFactoryBean] while setting bean property 'jobService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.framework.ProxyFactoryBean#7807ac2c': Post-processing of FactoryBean's object failed; nested exception is java.lang.IllegalStateException: @Scheduled method 'removeInactiveExecutions' found on bean target class 'SimpleJobService' but not found in any interface(s) for a dynamic proxy. Either pull the method up to a declared interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass to 'true'.

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <spring-batch-admin.version>2.0.0.BUILD-SNAPSHOT</spring-batch-admin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-admin-manager</artifactId>
            <version>${spring-batch-admin.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-admin-domain</artifactId>
            <version>${spring-batch-admin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>sqljdbc4</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots-local</id>
            <name>Spring Maven Snapshot Repository</name>
            <url>https://repo.spring.io/libs-snapshot-local/</url>
        </repository>
    </repositories>
</project>

Spring Boot config

@SpringBootApplication(exclude = {HypermediaAutoConfiguration.class, MultipartAutoConfiguration.class})
@EnableBatchAdmin
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

3 个答案:

答案 0 :(得分:1)

为了避免,JobController空指针异常,请放在

之下

server.servletPath = / *

祝你好运, Jigar。

答案 1 :(得分:1)

我终于找到了一种在maven项目中制作注释@EnableBatchAdmin的方法。

这允许您修复以下错误。

error-channel="errorChannel"

在此问题https://github.com/spring-projects/spring-batch-admin-samples/issues/12

中找到了解决方案

并将通过以下

覆盖 jmx-context.xml 文件
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchMBeanExporter' defined in URL [jar:file:/C:/Users/Admin/.m2/repository/org/springframework/batch/spring-batch-admin-manager/2.0.0.BUILD-SNAPSHOT/spring-batch-admin-manager-2.0.0.BUILD-SNAPSHOT.jar!/META-INF/spring/batch/bootstrap/manager/jmx-context.xml]: Cannot create inner bean 'org.springframework.aop.framework.ProxyFactoryBean#7807ac2c' of type [org.springframework.aop.framework.ProxyFactoryBean] while setting bean property 'jobService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.framework.ProxyFactoryBean#7807ac2c': Post-processing of FactoryBean's object failed; nested exception is java.lang.IllegalStateException: @Scheduled method 'removeInactiveExecutions' found on bean target class 'SimpleJobService' but not found in any interface(s) for a dynamic proxy. Either pull the method up to a declared interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass to 'true'.

将此代码放在main / resources / META-INF / spring / batch / override中的 jmx.context.xml 文件中

答案 2 :(得分:0)

最后,我能够使用spring batch admin运行spring批处理;虽然有this项目。仍然无法将@ EnableBatchAdmin与maven构建一起使用。非常感谢mminella和@vesperaba。

虽然我面临另一个问题;当我从存储库运行2.0.0.M1项目时,它工作正常。但是,当我在解析[JobController空指针异常](https://github.com/spring-projects/spring-batch-admin/pull/42)后在本地构建项目时;

  1. 我必须包含&#34; spring-batch-admin-resources&#34;在POM中明确; 虽然我运行应用程序时不是这种情况 repository(libs-snapshot-local)2.0.0.M1 建立。
  2. 当我包含&#34; spring-batch-admin-resources&#34;申请不是 能够开始说&#34; cvc-datatype-valid.1.2.1: &#39; /工作配置&#39;不是&#39; NCName&#39;。&#34;
  3. 的有效值

    任何意见将不胜感激。谢谢。