spring批量启动失败

af7jpaap  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(338)

我有一个非常令人沮丧的问题,一个在圣诞节前运行良好的spring批处理应用程序已经停止工作了。有一些变化,但我试图恢复所有这些,没有任何工作。
我有一个步骤:

<batch:step id="customerCampaignFileWritingStep">
        <batch:tasklet>
            <batch:chunk writer="customerCampaignFileWriter"
                         commit-interval="1000"
                         reader="tokenisedDatabaseReader" />
            <batch:listeners>
                <batch:listener ref="springBatchStepTimerListener"/>
                <batch:listener ref="customerCampaignFileCleanupListener"/>
            </batch:listeners>
        </batch:tasklet>
        <batch:next on="*" to="customerCampaignLoadToProductionTransferStep"/>
        <batch:next on="FAILED" to="loadingRepositoryClearDownStep"/>
    </batch:step>

读取器在javaconfig中定义:
读卡器:

@Bean
@StepScope
public ItemReader<CustomerCampaignLoad> tokenisedDatabaseReader (
        @Value("#{jobParameters['customerCampaign_input_file']}") String inputFileName
) {
    HibernatePagingItemReader<CustomerCampaignLoad> reader = new HibernatePagingItemReader();
    reader.setQueryString("from CustomerCampaignLoad where fileName = :filename");
    reader.setPageSize(1000);
    reader.setUseStatelessSession(true);
    SessionFactory fact = this.entityManagerFactory.getNativeEntityManagerFactory().unwrap(SessionFactory.class);
    reader.setSessionFactory(fact);
    //p:sessionFactory-ref="sessionFactory"

    Map<String, Object> paramVals = new HashMap<>();
    paramVals.put("filename", inputFileName);
    reader.setParameterValues(paramVals);

    return reader;
}

作者:

@Bean
@StepScope
public ResourceAwareItemWriterItemStream<CustomerCampaignLoad> customerCampaignFileWriter(
        @Value("#{jobParameters['customerCampaign_results_file']}") String fullyQualifiedResourceName,
        @Value("#{jobParameters['generic_step_scope_results_file_field_delimiter']}") String outputFileDelimiter,
        @Value("#{jobParameters['customerCampaign_field_names']}") String outputFileHeaderFields,
        @Value("#{jobParameters['customerCampaign_field_token_name']}") String entityTokenFieldName) {

    final FlatFileItemWriter<CustomerCampaignLoad> flatFileItemWriter = new FlatFileItemWriter<>();
    final DelimitedLineAggregator<CustomerCampaignLoad> delimitedLineAggregator = new DelimitedLineAggregator<>();

    delimitedLineAggregator.setDelimiter(outputFileDelimiter);

    // Here's where you customise the output file fields.
    delimitedLineAggregator.setFieldExtractor(customerCampaign -> new String[] {
            customerCampaign.getCustomerNumber(),
            customerCampaign.getCampaignId(),
            customerCampaign.getCampaignExpiry().toString(),
            customerCampaign.getCampaignName(),
            customerCampaign.getCampaignBatch(),
            customerCampaign.getCrn(),
            customerCampaign.getStoreEposNumber(),
            customerCampaign.getToken()
    });

    flatFileItemWriter.setLineAggregator(delimitedLineAggregator);
    flatFileItemWriter.setResource(new FileSystemResource(fullyQualifiedResourceName));
    final FlatFileHeaderCallback flatFileHeaderCallBack
            = writer -> writer.write(outputFileHeaderFields+","+entityTokenFieldName);
    flatFileItemWriter.setHeaderCallback(flatFileHeaderCallBack);
    flatFileItemWriter.setShouldDeleteIfExists(true);
    flatFileItemWriter.setAppendAllowed(false);

    return flatFileItemWriter;
}

启动错误为:

2021-01-17 10:26:44,038 ERROR [main] o.s.boot.SpringApplication Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerCampaignfileWritingStep': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy233 implementing org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.batch.item.ItemWriter' for property 'itemWriter'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy233 implementing org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.batch.item.ItemWriter' for property 'itemWriter': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:878)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.specsavers.digital.data.ingest.launch.Application.main(Application.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)

看起来被注入的writer不是接口,因为异常中列出的那些writer不包含所需的类型。但它被声明为一个接口。
唯一可能是xml和javaconfig的混合。但效果不错。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题