I have the following classes in different packages:
@EnableWebMvc
public class ActuatorConfig
{
// empty
// only needed to get REST so I can hit Actuator endpoints
}
@Component // REMOVE THIS LINE?
@EnableBatchProcessing
public class BatchConfig
{
// empty
}
@Component
@Configuration
public class ScheduleJob
{
@Autowired
private JobBuilderFactory jobBuilder;
@Bean
protected JobExecutionListener scheduleJobListener()
{
return new ScheduleJobListener();
}
}
(EDIT: Added Application class)
@SpringBootApplication
public class AfxApplication
{
public static void main(String[] args)
{
SpringApplication.run(AfxApplication.class, args);
}
}
The first class turns on Actuator features. I don't need any other annotations.
However, if I remove @Component from BatchConfig as noted above, Boot won't start because it can't find the dependency on JobBuilderFactory that it needs in order to populate the @Autowired ScheduleJob.jobBuilder.
The exception:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.configuration.annotation.JobBuilderFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 25 common frames omitted
When is @Component needed and when isn't it needed?
(I pulled out the @Enable* annotations because I'm trying to run unit tests that don't need all features enabled, and this way I can specify the features I want to enable by using @ComponentScan(basePackageClasses).)