org.springframework.beans.factory.unsatifiedDependencyException:创建名为';scopedTarget.slaveWriter';在类路径资源中定义
我使用的是SpringBoot批处理示例。在本例中,我使用PartitionedRange 在执行批处理作业时,我得到以下错误。Spring Boot版本2.0.3.0已发布。如果需要其他的,请告诉我 不确定这是为什么造成这些问题 这里出现的错误org.springframework.beans.factory.unsatifiedDependencyException:创建名为';scopedTarget.slaveWriter';在类路径资源中定义,spring,spring-boot,spring-batch,Spring,Spring Boot,Spring Batch,我使用的是SpringBoot批处理示例。在本例中,我使用PartitionedRange 在执行批处理作业时,我得到以下错误。Spring Boot版本2.0.3.0已发布。如果需要其他的,请告诉我 不确定这是为什么造成这些问题 这里出现的错误 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.slaveWriter' def
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.slaveWriter' defined in class path resource [com/prateek/job/PaymentsPartitionerJob.class]: Unsatisfied dependency expressed through method 'slaveWriter' parameter 1; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'stepExecutioUsertext': 'Invalid property 'stepExecutioUsertext' of bean class [org.springframework.batch.core.scope.context.StepContext]: Bean property 'stepExecutioUsertext' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?'
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:470) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1254) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:353) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) ~[spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:672) ~[spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.batch.item.file.FlatFileItemWriter$$EnhancerBySpringCGLIB$$c7405dad.open(<generated>) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103) ~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197) ~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:139) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:136) [spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'stepExecutioUsertext': 'Invalid property 'stepExecutioUsertext' of bean class [org.springframework.batch.core.scope.context.StepContext]: Bean property 'stepExecutioUsertext' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?'
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1452) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1088) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 19 common frames omitted
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'stepExecutioUsertext': 'Invalid property 'stepExecutioUsertext' of bean class [org.springframework.batch.core.scope.context.StepContext]: Bean property 'stepExecutioUsertext' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?'
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:209) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:52) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:111) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:270) ~[spring-expression-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 24 common frames omitted
org.springframework.beans.factory.unsatifiedDependencyException:创建名为“scopedTarget.slaveWriter”的bean时出错,该bean在类路径资源[com/pratek/job/PaymentsPartitionerJob.class]中定义:通过方法“slaveWriter”参数1表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常为org.springframework.expression.spel.SpelEvaluationException:EL1021E:尝试访问bean类[org.springframework.batch.core.scope.context.StepContext]的属性“StepExecutionerText”时出现问题:“无效属性”StepExecutionerText]:Bean属性“StepExecutionUserText”不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配
在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:470)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1254)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:353)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.aop.target.SimpleBanTargetSource.getTarget(SimpleBanTargetSource.java:35)~[spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:672)~[spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.batch.item.file.FlatFileItemWriter$$EnhancerBySpringCGLIB$$c7405dad.open()~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)~[spring-batch-infrastructure-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197)~[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
位于org.springframework.batch.core.partition.support.taskExecutionPartitionHandler$1.call(taskExecutionPartitionHandler.java:139)[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在org.springframework.batch.core.partition.support.taskExecutionPartitionHandler$1.call(taskExecutionPartitionHandler.java:136)[spring-batch-core-4.0.1.RELEASE.jar:4.0.1.RELEASE]
在java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0_171]
在java.lang.Thread.run(Thread.java:748)[na:1.8.0_171]
原因:org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常为org.springframework.expression.spel.SpelEvaluationException:EL1021E:尝试访问bean类[org.springframework.batch.core.scope.context.StepContext]的属性“StepExecutionerText”时出现问题:“无效属性”StepExecutionerText]:Bean属性“StepExecutionUserText”不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配
在org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164)~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1452)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1088)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
在org.springframework.beans.factory.support.ConstructorResolver.creat上
@Slf4j
@Configuration
@EnableBatchProcessing
public class PaymentsPartitionerJob {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private DataSource dataSource;
@Bean
public SimpleAsyncTaskExecutor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}
@Bean
public RangePartitioner rangePartitioner() {
return new RangePartitioner();
}
@Bean
public PaymentsTasklet paymentsTasklet() {
return new PaymentsTasklet();
}
@Bean
@StepScope
public PaymentProcessor slaveProcessor(@Value("#{stepExecutionContext[name]}") String name) {
log.info("********called slave processor **********");
PaymentProcessor paymentProcessor = new PaymentProcessor();
paymentProcessor.setThreadName(name);
return paymentProcessor;
}
@Bean
@StepScope
public FlatFileItemWriter<Payments> slaveWriter(@Value("#{stepExecutionContext[fromId]}") final String fromId,
@Value("#{stepExecutioUsertext[toId]}") final String toId){
FlatFileItemWriter<Payments> reader = new FlatFileItemWriter<>();
reader.setResource(new FileSystemResource("csv//payments.processed"+ fromId+"-"+toId+".csv"));
BeanWrapperFieldExtractor<Payments> fieldExtractor = new BeanWrapperFieldExtractor<>();
fieldExtractor.setNames(new String[] {"customerNumber", "checkNumber", "paymentDate", "amount"});
DelimitedLineAggregator<Payments> lineAggregator = new DelimitedLineAggregator<>();
lineAggregator.setDelimiter(",");
lineAggregator.setFieldExtractor(fieldExtractor);
return reader;
}
@Bean
@StepScope
public JdbcPagingItemReader<Payments> slaveReader(@Value("#{stepExecutionContext[fromId]}") final String fromId,
@Value("#{stepExecutionContext[toId]}") final String toId,
@Value("#{stepExecutionContext[name]}") final String name) {
// Bean Property Row Mapper
BeanPropertyRowMapper<Payments> propertyRowMapper = new BeanPropertyRowMapper<>();
propertyRowMapper.setMappedClass(Payments.class);
log.info("slaveReader start " + fromId + " " + toId);
// Jdbc Paging Item Reader
JdbcPagingItemReader<Payments> reader = new JdbcPagingItemReader<>();
reader.setDataSource(dataSource);
reader.setQueryProvider(queryProvider());
// Set the Parameter values
Map<String, Object> parameterValues = new HashMap<>();
parameterValues.put("fromId", fromId);
parameterValues.put("toId", toId);
log.info("Parameter Value " + name + " " + parameterValues);
reader.setParameterValues(parameterValues);
reader.setPageSize(1000);
reader.setRowMapper(propertyRowMapper);
return reader;
}
private PagingQueryProvider queryProvider() {
log.info("queryProvider start ");
SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean();
provider.setDataSource(dataSource);
provider.setSelectClause("SELECT customerNumber, checkNumber, paymentDate, amount ");
provider.setFromClause("FROM payments ");
provider.setWhereClause("WHERE customerNumber >= :fromId AND fromId <= :toId ");
provider.setSortKey("customerNumber");
try {
return provider.getObject();
} catch (Exception e) {
log.error("ERROR IN queryProvider() "+e.getMessage());
}
return null;
}
@Bean(name = "slave")
public Step slave() {
log.info("...........called slave .........");
return stepBuilderFactory.get("slave").<Payments, Payments>chunk(100)
.reader(slaveReader(null, null, null))
.processor(slaveProcessor(null))
.writer(slaveWriter(null, null))
.build();
}
@Bean
public PartitionHandler masterSlaveHandler() {
TaskExecutorPartitionHandler handler = new TaskExecutorPartitionHandler();
handler.setGridSize(10);
handler.setTaskExecutor(taskExecutor());
handler.setStep(slave());
try {
handler.afterPropertiesSet();
} catch (Exception e) {
log.error("masterSlaveHandler :: "+e.getMessage());
}
return handler;
}
@Bean
public Step masterStep() {
return stepBuilderFactory.get("masterStep")
.partitioner(slave().getName(), rangePartitioner())
.partitionHandler(masterSlaveHandler())
.build();
}
@Bean
public Step step2() {
return stepBuilderFactory.get("step2").tasklet(paymentsTasklet()).build();
}
@Bean
public Job PartitionJob() {
return jobBuilderFactory
.get("partitionJob")
.incrementer(new RunIdIncrementer())
.start(masterStep())
.next(step2())
.build();
}
}
@Value("#{stepExecutionContext['name']}") String name
@Bean
@StepScope
public FlatFileItemWriter<Payments> slaveWriter(@Value("#{stepExecutionContext[fromId]}") final String fromId,
@Value("#{stepExecutioUsertext[toId]}") final String toId)
@Bean
@StepScope
public FlatFileItemWriter<Payments> slaveWriter(@Value("#{stepExecutionContext[fromId]}") final String fromId,
@Value("#{stepExecutionContext[toId]}") final String toId)