【问题标题】:Spring Batch Admin (2.0.0.M1): error creating bean batchMBeanExporterSpring Batch Admin (2.0.0.M1):创建 bean batchMBeanExporter 时出错
【发布时间】:2016-04-09 12:23:41
【问题描述】:

我正在尝试从 Spring Boot 应用程序运行 Spring Batch Admin。

我正在使用来自 Michael (@mminella) 的 this 优秀示例。此应用程序运行良好。

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

我看到的唯一区别是 spring-batch-core 的版本。使用 maven,它的版本是 3.0.6,而使用 gradle(Michael 的应用程序)的版本是 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 配置

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

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

【问题讨论】:

  • 最后,我能够使用 spring batch admin 运行 spring batch;虽然有this 项目。仍然无法在 Maven 构建中使用 @EnableBatchAdmin。非常感谢 mminella 和 @vesperaba。谢谢。

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


【解决方案1】:

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

server.servletPath=/*

最好的问候, 吉格。

【讨论】:

    【解决方案2】:

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

    这允许您修复以下错误。

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

    在本期https://github.com/spring-projects/spring-batch-admin-samples/issues/12找到解决方法

    并且是通过以下方式覆盖jmx-context.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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    <context:mbean-server id="mbeanServer"/>
    
    <context:mbean-export default-domain="spring.application" server="mbeanServer"/>
    
    <!-- Override the `batchMBeanExporter` and set the `proxyTargetClass` property to true on the `jobService` proxy.
        This is a workaround for the related https://jira.spring.io/browse/BATCHADM-126 -->
    <bean id="batchMBeanExporter" class="org.springframework.batch.admin.jmx.BatchMBeanExporter">
        <property name="server" ref="mbeanServer"/>
        <property name="jobService">
            <bean class="org.springframework.aop.framework.ProxyFactoryBean">
                <property name="targetName" value="jobService"/>
                <property name="proxyTargetClass" value="true"/>
            </bean>
        </property>
        <property name="defaultDomain" value="spring.application"/>
    </bean>
    

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

    【讨论】:

      【解决方案3】:

      最后,我能够使用 spring batch admin 运行 spring batch;虽然有this 项目。仍然无法在 Maven 构建中使用 @EnableBatchAdmin。非常感谢 mminella 和 @vesperaba。

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

      1. 我必须在 POM 中明确包含“spring-batch-admin-resources”; 而当我使用运行应用程序时情况并非如此 存储库 (libs-snapshot-local) 2.0.0.M1 建造。
      2. 当我包含“spring-batch-admin-resources”应用程序不是 能够开始说“cvc-datatype-valid.1.2.1: '/job-configuration' 不是 'NCName' 的有效值。”

      任何 cmets 将不胜感激。谢谢。

      【讨论】:

        猜你喜欢
        • 2014-03-22
        • 2016-06-24
        • 2013-10-06
        • 2017-02-03
        • 2015-02-27
        • 2020-03-14
        • 1970-01-01
        • 2012-08-07
        • 2015-05-28
        相关资源
        最近更新 更多