mercredi 25 février 2015

Avoid duplication using Spring and Java Config beans

I am having in Class A the following beans:



@Bean
public AsyncItemProcessor OneUploadAsyncItemProcessor() {

...
asyncItemProcessor.setDelegate(processor(OVERRIDDEN_BY_EXPRESSION, OVERRIDDEN_BY_EXPRESSION));
....

return asyncItemProcessor;

}

@Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES)
@Bean
public ItemProcessor<MyItem, MyItem> processor(@Value("#{jobParameters[pushMessage]}") String pushMessage,
@Value("#{jobParameters[jobId]}") String jobId,
) {
return new PushItemProcessor(pushMessage, jobId);
}\\\


Now I have in a class B the following:



@Bean
public AsyncItemProcessor TwpUploadAsyncItemProcessor() {

....
asyncItemProcessor.setDelegate(processor(OVERRIDDEN_BY_EXPRESSION, OVERRIDDEN_BY_EXPRESSION));


return asyncItemProcessor;

}


How I can Inject into class B the bean processor (which defined on class A) without duplicate it.


Aucun commentaire:

Enregistrer un commentaire