2014-12-10 2 views
2

Я пытаюсь запустить приложение Spring Batch Admin с Spring Boot, и похоже, что у меня такая же проблема. Предпочтительным решением было бы использовать конфигурацию Java вместо XML.Spring Batch 3.0.2 интеграция с Spring Core 4.1.x - Каким образом можно использовать @EnableBatchProcessing?

Что было бы подходящим решением для использования @EnableBatchProcessing с Spring Batch Admin?

Я посмотрел на this question, но я не смог решить проблему.

Заранее спасибо.

Spring конфигурации Batch:

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

ответ

5

Работа пример (@EnableBatchProcessing удаляется, JobBuilderFactory и StepBuilderFactory создаются в конфигурации Java):

@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); 
    } 
} 
+0

Как вы узнали об этом в мире? Я не мог понять, глядя на журналы, что это должно решить проблему – JavaTec

1

ошибка, вы получаете то, потому что @EnableBatchProcessing регистрирует StepScope и так делает Spring Batch Admin. Как я упоминал в сообщении, на которое вы ссылались, я бы не рекомендовал использовать @EnableBatchProcessing с Spring Batch Admin и вместо этого просто настроить необходимые вам компоненты (только фабрика фабрик и фабрика шагов).

+0

Это помогло. Благодарю. Но теперь в Spring Batch Admin UI не заданы рабочие задания (рабочие задания и этапы создаются на Java, не определенные в XML). Что мне делать, чтобы исправить это? – Ivan

+0

Работает, возникла проблема с сканированием пакетов. Я отправлю пример рабочего решения. Еще раз спасибо. – Ivan

+0

Привет, Майкл, есть ли обновление об исправлении? Когда запланированная дата выпуска версии с исправлением? – MFIhsan

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