0

**I am getting below error even though i have down the @autowired .please some one let me know why this issue happening its a ant build with spring config utor. 2022-07-08 10:18:09,856 WARN org.springframework.context.support. ClassPathXmlApplicationContext - Exception encountered during context initialization

  • cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'delegateProcessor': Unsatisfied dependency expressed through field 'headerProcessor'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [org.springframework.batch.item.ItemProcessor<com.abc.proj.model.FileHeader, com.abc.proj.model.FileHeader>]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=headerProcessor)} Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'delegateProcessor': Unsatisfied dependency expressed through field 'headerProcessor'; nested exception is org.springframework.beans.factory. NoSuchBeanDefinitionException: No qualifying bean found for dependency [org.springframework.batch.item.ItemProcessor<com.abc.proj.model.FileHeader, com.abc.proj.model.FileHeader>]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=headerProcessor)}

@Component
public class DelegateProcessor implements ItemProcessor<Object, Object>, InitializingBean {
    @Autowired
    @Qualifier("headerProcessor")
    private ItemProcessor<FileHeader, FileHeader> headerProcessor;
    @Autowired
    @Qualifier("detailProcessor")
    private ItemProcessor<FileDetail, FileDetail> detailProcessor;
    @Autowired
    @Qualifier("trailerProcessor")
    private ItemProcessor<FileTrailer, FileTrailer> trailerProcessor;

@Component
public class HeaderProcessor implements  ItemProcessor<Object, Object>{
    @Autowired
    private HeaderValidatorDao headerValidatorDao ;**
Onr
  • 1
  • 3
  • You need to create manually instances of ItemProcessor with those names "headerProcessor", "detailProcessor", "trailerProcessor" – CaptainPyscho Jul 10 '22 at 01:43
  • @CaptainPyscho can you please explain little more in detail on how to do it ..Thank you – Onr Jul 10 '22 at 02:42

1 Answers1

0

With a configuration class you could initialize your beans manually, specially if they need custom names.

@Configuration
public class MyCustomConfiguration {
   
   @Bean(name ="headerProcessor")
   public ItemProcessor<FileHeader, FileHeader> headerProcessorBean() {
      ItemProcessor<FileHeader, FileHeader> myBean = new HeaderProcessor<>();
      //Do whaterever you need to initilize your bean
      return myBean;
   }

   @Bean(name ="detailProcessor")
   public ItemProcessor<FileDetail, FileDetail> detailProcessorBean() {
      ItemProcessor<FileDetail, FileDetail> myBean = new ItemProcessor<>();
      //Do whaterever you need to initilize your bean
      return myBean;
   }
}

In this way these beans will be available for autowiring.

CaptainPyscho
  • 338
  • 1
  • 7