2014-12-31 4 views
3

Я пытаюсь объединить команду spring-batch-admin-manager с функцией spring-boot-starter-batch вместе с использованием встроенной конфигурации tomcat с пружинной загрузкой.Ошибка Интеграция Spring-партии с Spring-batch-admin-manager в Spring-boot

Однако я есть этот след ошибки, которые я не могу прибить:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.mycompany.notification.processor.service.batch.configuration.BatchConfiguration.steps; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$6da887a9 cannot be cast to org.springframework.batch.core.repository.JobRepository 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:961) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:950) 
    at com.mycompany.notification.processor.service.main.Application.main(Application.java:27) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.configuration.annotation.StepBuilderFactory com.mycompany.notification.processor.service.batch.configuration.BatchConfiguration.steps; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$6da887a9 cannot be cast to org.springframework.batch.core.repository.JobRepository 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:558) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 21 common frames omitted 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepBuilders' 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.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$6da887a9 cannot be cast to org.springframework.batch.core.repository.JobRepository 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:602) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:530) 
    ... 23 common frames omitted 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.StepBuilderFactory]: Factory method 'stepBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$6da887a9 cannot be cast to org.springframework.batch.core.repository.JobRepository 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) 
    ... 35 common frames omitted 
Caused by: java.lang.ClassCastException: org.springframework.batch.core.repository.support.JobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$6da887a9 cannot be cast to org.springframework.batch.core.repository.JobRepository 
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$607a70b7.jobRepository(<generated>) 
    at org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.stepBuilders(AbstractBatchConfiguration.java:63) 
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$607a70b7.CGLIB$stepBuilders$7(<generated>) 
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$607a70b7$$FastClassBySpringCGLIB$$ac8c0a6a.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$607a70b7.stepBuilders(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 36 common frames omitted 

Это мой Gradle файл сборки:

buildscript { 
    repositories { 
     mavenCentral() 
     maven { url 'http://repo.spring.io/milestone/' } 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.0.RELEASE") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 

war { 
    baseName = 'notification-processor-service' 
    version = '1.0.0-SNAPSHOT' 
} 
jar { 
    baseName = 'notification-processor-service' 
    version = '1.0.0-SNAPSHOT' 
} 

ext { 
    springIntegrationVersion = '4.1.1.RELEASE' 
    springIntegrationKafkaVersion = '1.0.0.M2' 
} 

repositories { 
    mavenCentral() 
    maven { 
     url 'https://repository.apache.org/content/groups/public' 
    } 
    maven { url 'http://repo.spring.io/milestone/' } 
} 

dependencies { 
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-batch:1.2.0.RELEASE") 
    compile("org.springframework.boot:spring-boot-starter-actuator") 
    compile("javax.inject:javax.inject:1") 
    compile('org.springframework.batch:spring-batch-admin-manager:1.3.0.RELEASE') { 
     exclude module: 'slf4j-log4j12' 
    } 
    //SI 
    // compile("org.springframework.integration:spring-integration-core:$springIntegrationVersion") 

    /* //kafka 
    compile("org.springframework.integration:spring-integration-kafka:$springIntegrationKafkaVersion") { 
     exclude module: 'log4j' 
     exclude module: 'jms' 
     exclude module: 'jmxtools' 
     exclude module: 'jmxri' 
    }*/ 
    testCompile("org.springframework.boot:spring-boot-starter-test") 

} 

task wrapper(type: Wrapper) { 
    gradleVersion = '1.11' 
} 

Я добавил эти конфигурации, как показано в этом GitHub, например:

https://github.com/codecentric/spring-batch-admin-spring-boot

@Configuration 
@ImportResource("classpath:/org/springframework/batch/admin/web/resources/servlet-config.xml") 
public class ServletConfiguration { 
} 

*/ 
@Configuration 
@ImportResource("classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml") 
public class WebappConfiguration { 

} 

это мой batchConfiguration класс:

@EnableBatchProcessing 
@Configuration 
public class BatchConfiguration { 

    private static final Logger logger = LoggerFactory.getLogger(BatchConfiguration.class); 

    @Inject 
    WriteToKafkaTasklet writeToKafkaTasklet; 

    @Autowired 
    private StepBuilderFactory steps; 


    @Autowired 
    private JobBuilderFactory jobs; 

    @Autowired 
    private StepBuilderFactory stepBuilderFactory; 


} 

Что мне не хватает?

+0

У вас есть пример кода, где вы получили эту функцию spring-batch-admin и spring-batch? спасибо –

ответ

4

Пара вещей здесь:

  1. Не используйте @EnableBatchProcessing с Spring Batch администратора. SBA предоставляет несколько компонентов из коробки. Если вы хотите использовать самую последнюю и самую лучшую, она обеспечивает все, что @EnableBatchProcessing обеспечивает без использования аннотации.
  2. Трассировка стека, которую вы получаете, связана с тем, что @EnableBatchProcessing регистрирует StepScope, который использует динамическое подклассу, но Spring Batch Admin также регистрирует StepScope, который использует java-прокси. Как уже упоминалось, удалите @EnableBatchProcessing и удалите трассировку стека.

Если вы используете в настоящее время выпущенные компоненты, то после удаления @EnableBatchProcessing вам необходимо вручную настроить два создаваемых им сборщика. Добавьте следующий XML для переопределения XML, и вы должны быть в бизнесе:

<bean id="jobBuilderFactory" class="org.springframework.batch.core.configuration.annotation.JobBuilderFactory"> 
    <constructor-arg ref="jobRepository"/> 
</bean> 

<bean id="stepBuilderFactory" class="org.springframework.batch.core.configuration.annotation.StepBuilderFactory"> 
    <constructor-arg index="0" ref="jobRepository"/> 
    <constructor-arg index="1" ref="transactionManager"/> 
</bean> 

Следите за Spring Batch Администратор 2.0. В этом будет все, что обсуждается здесь. M1 должен появиться в ближайшие пару недель.

+0

Вы бы посмотрели http://stackoverflow.com/questions/27729750/best-approach-using-spring-batch-to-process-big-file/27736756#27736756 спасибо. – rayman

Смежные вопросы