我一直在尝试进行设置,在其中创建实现 JdbcCursorItemReader 的 PostDatedAchInReader,然后将其注入 PostDatedAchInAggregatingJdbcItemReader,后者根据特定标准收集读取对象并将它们分组到一个列表中,该列表基本上按客户端 ID 保留所有 ach 请求组。但是,我不断收到 no qualifying bean 错误,但 bean 在这里并已定义。我很困惑问题是什么或如何解决它。
所以我有以下配置文件
@Configuration
public class PostDatedAchInBatchConfig extends AbstractCommonBatchJobConfig {
private static final String ACH_FULFILLMENT_POST_DATED_ACH_IN_STEP1_NAME =
"achFulfillment_postDatedAchInJob_step1_scheduleAchIns";
@Autowired
DataSource prodDataSource;
/**
* This method defines the Job.
*
* @return postdatedachinjob
* return the configured job.
*/
@Bean(name = "achFulfillmentPostDatedAchInJob")
public Job job() throws Exception {
mmLogMgr.info("AchFulfillmentEmailBatchConfig : job");
return getJobBuilderFactory().get("achFulfillmentPostDatedAchInJob")
.listener(postDatedAchInListener())
.start(step1())
.on(ExitStatus.COMPLETED.getExitCode())
.end() // end of TransactionBuilder
.end() // end of FlowBuilder
.build();
}
..
/**
* @return postDatedAchInAggregatingJdbcItemReader.
*/
@Bean
@Scope(value = "step", proxyMode = ScopedProxyMode.DEFAULT)
public ItemReader<ArrayList<PostDatedAchIn>> postDatedAchInAggregatingJdbcItemReader(@Qualifier("postDatedAchInReader") final PostDatedAchInReader postDatedAchInReader)
throws Exception {
PostDatedAchInAggregatingJdbcItemReader postDatedAchInAggregatingJdbcItemReader =
new PostDatedAchInAggregatingJdbcItemReader();
postDatedAchInAggregatingJdbcItemReader.setDatabaseItemReader(postDatedAchInReader);
return postDatedAchInAggregatingJdbcItemReader;
}
@Bean
public PostDatedAchInClassifierWriter postDatedAchInClassifierWriter() {
Map<String, ItemWriter<PostDatedAchIn>> classMap = new HashMap<String, ItemWriter<PostDatedAchIn>>();
classMap.put("true", postDatedAchInCompositeWriterOneTimeFailure());
classMap.put("false", postDatedAchInCompositeWriterPosted());
PostDatedAchInClassifierWriter classifyWriter = new PostDatedAchInClassifierWriter();
classifyWriter.setClassMap(classMap);
return classifyWriter;
}
..
@Bean(name = "postDatedAchInReader")
@Scope(value = "step", proxyMode = ScopedProxyMode.DEFAULT)
public PostDatedAchInReader postDatedAchInReader(@Value("#{jobExecutionContext['current.business.date']}") final String currentBusinessDate) {
SqlStatementHelper sqlStatementHelper = new SqlStatementHelper(PostDatedAchInConstants.POST_DATED_ACH_IN_PROPERTY_FILE,
PostDatedAchInConstants.POST_DATED_ACH_IN_PROPERTY_ALT_FILE);
String sqlStatement = sqlStatementHelper.getSqlStatement(PostDatedAchInConstants.RETRIEVE_POST_DATED_ACH_IN);
ArrayList<String> parameters = new ArrayList<String>();
parameters.add(currentBusinessDate);
parameters.add(currentBusinessDate);
parameters.add(currentBusinessDate);
ListPreparedStatementSetter preparedStatementSetter = new ListPreparedStatementSetter();
preparedStatementSetter.setParameters(parameters);
PostDatedAchInReader postDatedAchInReader = new PostDatedAchInReader();
postDatedAchInReader.setDataSource(prodDataSource);
postDatedAchInReader.setSql(sqlStatement);
postDatedAchInReader.setRowMapper(new PostDatedAchInRowMapper());
postDatedAchInReader.setPreparedStatementSetter(preparedStatementSetter);
return postDatedAchInReader;
}
/**
* This method defines the Steps, it writes 1 record at a time.
*
* @return postdatedachinjob_step1
*
*/
@Bean(name = ACH_FULFILLMENT_POST_DATED_ACH_IN_STEP1_NAME)
public Step step1() throws Exception {
mmLogMgr.info(ACH_FULFILLMENT_POST_DATED_ACH_IN_STEP1_NAME);
return getStepBuilderFactory().get(ACH_FULFILLMENT_POST_DATED_ACH_IN_STEP1_NAME)
.<ArrayList<PostDatedAchIn>, ArrayList<PostDatedAchIn>> chunk(AchFulfillmentBatchJobUtil
.getChunkValue("postdatedachin"))
.reader(postDatedAchInAggregatingJdbcItemReader(null))
.processor(postDatedAchInProcessor())
.writer(postDatedAchInClassifierWriter())
.build();
}
}
当我运行作业时,我得到以下堆栈跟踪:
2018-10-31 15:06:45,821 ERROR [o.s.batch.core.step.AbstractStep:AbstractStep.java:execute:229 - main] - Encountered an error executing step achFulfillment_postDatedAchInJob_step1_scheduleAchIns in job achFulfillmentPostDatedAchInJob
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.postDatedAchInAggregatingJdbcItemReader' defined in com.tdameritrade.ctg.ach.batch.postdatedachinjob.PostDatedAchInBatchConfig: Unsatisfied dependency expressed through method 'postDatedAchInAggregatingJdbcItemReader' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tdameritrade.ctg.ach.batch.postdatedachinjob.PostDatedAchInReader' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=postDatedAchInReader)}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:345)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
at com.sun.proxy.$Proxy112.read(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91)
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157)
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at com.tdameritrade.ctg.ach.fulfillment.util.MoneyMovementHelper.getJobExecution(MoneyMovementHelper.java:155)
at com.tdameritrade.ctg.ach.fulfillment.util.MoneyMovementHelper.getJobExecution(MoneyMovementHelper.java:136)
at com.tdameritrade.ctg.ach.batch.postdatedachinjob.PostDatedAchInBatchConfigTest.testLaunchJob(PostDatedAchInBatchConfigTest.java:32)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tdameritrade.ctg.ach.batch.postdatedachinjob.PostDatedAchInReader' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=postDatedAchInReader)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 72 common frames omitted
我很困惑它是如何说它在类中正确定义时找不到该类型的 bean。
我怎样才能解决这个问题?