Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-issuemaster opened this issue Nov 6, 2012 · 2 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 6, 2012

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:

<job id="job1" xmlns="http://www.springframework.org/schema/batch" incrementer="incrementer">
<!-- Main step -->

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

<!-- Listener for the job -->
<listeners>
<listener ref="commonJobListener" />
</listeners>
</job>
<!-- ItemWriter -->
<bean id="itemWriter1" class="org.springframework.batch.item.file.FlatFil eItemWriter" scope="step">
<property name="resource" value="file:#{jobExecutionContext['timestampDir']}${output.file}" />

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

</bean>

THE ITEM PROCESS CODE:

@Autowired
FlatFileItemWriter<FicheroOperacionesFilaSalida> 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-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 4, 2013

Charles Lee commented

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

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 4, 2013

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.