spring-projects / spring-batch

Spring Batch is a framework for writing batch applications using Java and Spring
http://projects.spring.io/spring-batch/
Apache License 2.0
2.73k stars 2.35k forks source link

Cannot autowire a delegate ItemWriter defined with step scope [BATCH-1905] #1691

Closed spring-projects-issues closed 10 years ago

spring-projects-issues commented 12 years ago

MARTIN JUIZ opened BATCH-1905 and commented

I have a problem when I try to @Autowired a bean of type FlatFileItemWriter. I need to calculate a directory name in execution time and assign this value to the "resource" property using late-binding. There's no problem to achive this, but, when my batch runs, I receive an exception when Spring context tries to @Autowired this bean inside my ItemProcessor (I need to use it directly in the ItemProcessor for functional design)

The exception is: There are many candidates of type org.springframework...FlatFileItemWriter.

If I use the @Qualifier then the error refers to another bean that has no sense with that error.

My ItemWriter works as "delegate". I couldn't write items during the process because I need to process all the items first to do some operations.

Why do an ItemWriter cannot be autowired if this bean is defined with late-binding?

==========================================================================

==========================================================================

The code is:

LISTENER TO BUILD THE DIRECTORY NAME:

@BeforeJob void beforeJob(JobExecution jobExecution) { String dirTimestamp = BatchUtil.getInstance().getFormattedDate(new Date(), BatchConstants.DATE_FORMAT6); ExecutionContext executionContext = jobExecution.getExecutionContext(); executionContext.putString(batchConfig.nombreDirTi mestamp, dirTimestamp + "/"); }

THE XML CONFIG OF THE JOB:

\ \

<step id="step1" ..../>

\ \ \ \ \ \ \ \

......................

\

THE ITEM PROCESS CODE:

@Autowired FlatFileItemWriter\ itemWriter1;

If I don't use the late-binding in the bean, there's no problem to autowired it.


Affects: 2.1.8

Reference URL: http://forum.springsource.org/showthread.php?131462-Problem-autowiring-ItemWriter-defined-with-scope-quot-step-quot

spring-projects-issues commented 11 years ago

Charles Lee commented

I have posted my comments in the forum (see reference URL above). This is not a bug.

spring-projects-issues commented 11 years ago

MARTIN JUIZ commented

Hi Charles,

I just read your post and I'm gonna try it. I'll tell you the result...

Thanks in advance !!! :D

Regards,