0

I am using the spring-batch-admin-sample application as the starting point for a project. I have a working spring-batch job that is built with annotations that I am integrating with the console.

When I jar it up and add it to my console project, the annotations are not honored. In order to test this, I have gone as far as to add the tag to the job, so an attempt to build the job bean means that the annotation-config tag has been seen and processed.

Can anyone see what I am missing?

Thanks in advance.

Environment

OS: Windows 7
Java: jdk 1.8.0_25
Spring Batch Admin Sample version: 1.3.1
Spring version: 3.2.13   * stock 3.2.9 has a bug that causes this symptom 
Spring-batch version: 3.0.2
Pivotal tc version:  3.0 Developer Edition
IDE: STS 3.6.3

Log Snip:

14:27:13.667 [localhost-startStop-1] WARN  ... Error creating bean with name 'step0002-fetch': 
    **Cannot resolve reference to bean 'sourceSelectionReader'** 
    while setting bean property 'itemReader'; nested exception is 
    org.springframework.beans.factory.NoSuchBeanDefinitionException: 
    No bean named 'sourceSelectionReader' is defined

Job Bean Definition

<context:annotation-config/>

<bean class="org.springframework.batch.core.scope.StepScope" />


<batch:job id="my-job">
    <batch:step id="step0002-fetch"  >          
        <batch:tasklet transaction-manager="transactionManager" start-limit="100" >
            <batch:chunk reader="sourceSelectionReader" writer="selectedDataWriter" commit-interval="1" />
        </batch:tasklet>
        <batch:next on="*" to="step0003-archive-purge"/>
    </batch:step>
</batch:job

Class definition:

@Component("sourceSelectionReader")
@Scope(value="step", proxyMode = ScopedProxyMode.INTERFACES)
public class SourceSelectionReaderImpl  
    implements ItemReader<Object>,SourceSelectionReader, ApplicationContextAware {

...
}
pojo-guy
  • 966
  • 1
  • 12
  • 39

1 Answers1

1

The tag

<context:annotation-config/>

should have been

<context:component-scan/>

... looking for a rock to crawl under ...

See Difference between <context:annotation-config> vs <context:component-scan> for an explanation.

Community
  • 1
  • 1
pojo-guy
  • 966
  • 1
  • 12
  • 39
  • You might want to specify a base-package instead of scanning the whole class path. – M. Deinum Jan 28 '15 at 21:59
  • I only resorted to scanning the whole class path when things didn't seem to be working. Unfortunately, with Spring, the only symptom of any problem is "It doesn't work", so I had 5 different configuration issues resulting in the same symptom, including forgetting to add the jar with my business classes to the pom. This was the last link in the chhain, and all works well now. – pojo-guy Jan 29 '15 at 22:19