Java Spring Batch 3.0.2与Spring Core 4.1.x的集成-使用@EnableBatchProcessing的适当方式是什么?

Java Spring Batch 3.0.2与Spring Core 4.1.x的集成-使用@EnableBatchProcessing的适当方式是什么?,java,spring,spring-boot,spring-batch,Java,Spring,Spring Boot,Spring Batch,我正在尝试用SpringBoot运行SpringBatch管理应用程序,看起来我也遇到了同样的问题。首选的解决方案是使用Java配置,而不是XML 在Spring Batch Admin中使用@EnableBatchProcessing的合适解决方案是什么 我看了一下,但没能解决这个问题 先谢谢你 Spring批处理配置: @Configuration @EnableBatchProcessing @ImportResource({ "classpath:org/springfr

我正在尝试用SpringBoot运行SpringBatch管理应用程序,看起来我也遇到了同样的问题。首选的解决方案是使用Java配置,而不是XML

在Spring Batch Admin中使用@EnableBatchProcessing的合适解决方案是什么

我看了一下,但没能解决这个问题

先谢谢你

Spring批处理配置:

@Configuration
@EnableBatchProcessing
@ImportResource({
        "classpath:org/springframework/batch/admin/web/resources/servlet-config.xml",
        "classpath:org/springframework/batch/admin/web/resources/webapp-config.xml"
    })
public class BatchConfig {
}
@Configuration
@ImportResource(
        value = {
                "classpath:org/springframework/batch/admin/web/resources/servlet-config.xml",
                "classpath:org/springframework/batch/admin/web/resources/webapp-config.xml"
        }
    )
public class BatchConfiguration {
    @Bean
    public JobBuilderFactory jobBuilderFactory(JobRepository jobRepository) {
        return new JobBuilderFactory(jobRepository);
    }

    @Bean
    public StepBuilderFactory stepBuilderFactory(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
        return new StepBuilderFactory(jobRepository, transactionManager);
    }
}
Spring启动程序实现:

@Configuration
@EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class })
@Import(BatchConfiguration.class)
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return super.configure(application);
    }
}
堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.JobBuilderFactory]: Factory method 'jobBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40 cannot be cast to org.springframework.batch.core.repository.JobRepository
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:602) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:952) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) [spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
    at some.package.Application.main(FeedApplication.java:29) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.JobBuilderFactory]: Factory method 'jobBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40 cannot be cast to org.springframework.batch.core.repository.JobRepository
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    ... 17 common frames omitted
Caused by: java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40 cannot be cast to org.springframework.batch.core.repository.JobRepository
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2.jobRepository(<generated>) ~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
    at org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.jobBuilders(AbstractBatchConfiguration.java:58) ~[spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2.CGLIB$jobBuilders$8(<generated>) ~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2$$FastClassBySpringCGLIB$$606382af.invoke(<generated>) ~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2.jobBuilders(<generated>) ~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_72]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_72]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_72]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_72]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
    ... 18 common frames omitted
org.springframework.beans.factory.BeanCreationException:创建名为“jobBuilders”的bean时出错,该bean在类路径资源[org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanstantiationException:未能实例化[org.springframework.batch.core.configuration.annotation.JobBuilderFactory]:工厂方法“JobBuilder”引发异常;嵌套异常为java.lang.ClassCastException:org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40不能强制转换为org.springframework.batch.core.repository.JobRepository
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:602)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:762)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE]
位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)[spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)[spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:320)[spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:952)[spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:941)[spring-boot-1.1.9.RELEASE.jar:1.1.9.RELEASE]
在一些.package.Application.main(FeedApplication.java:29)[classes/:na]
原因:org.springframework.beans.beans实例化异常:未能实例化[org.springframework.batch.core.configuration.annotation.JobBuilderFactory]:工厂方法“JobBuilder”引发异常;嵌套异常为java.lang.ClassCastException:org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40不能强制转换为org.springframework.batch.core.repository.JobRepository
在org.springframework.beans.factory.support.SimpleInstallationStrategy.instantiate(SimpleInstallationStrategy.java:189)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:591)~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE]
... 省略17个公共框架
原因:java.lang.ClassCastException:org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$4421fb40无法强制转换为org.springframework.batch.core.repository.JobRepository
在org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2.jobRepository()~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
在org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.jobBuilders(AbstractBatchConfiguration.java:58)~[spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
在org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2.CGLIB$jobBuilders$8()~[spring-core-4.1.3.RELEASE.jar:3.0.2.RELEASE]
在org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$5a6187a2$$FastClassBySpringCGLIB$$606382af.invoke(