October 27, 2024
Chicago 12, Melborne City, USA
java

Java Spring expected at least 1 bean which qualifies as autowire candidate. Dependency annotations


Spring boot application throws No Qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate. error at runtime.

Please find my code below.

SpringBoot version : 2.7.9
JDK 11

public class CatalogServiceImpl extends CatalogService.CatalogServiceImplBase {

    private final DataSourceHandler dataSourceHandlerDelegate;

    private final StorefrontServiceHelper storefrontServiceHelper

    CatalogServiceImpl ( DataSourceHandler dataSourceHandlerDelegate, 
    StorefrontServiceHelper storefrontServiceHelper) {
    this.dataSourceHandlerDelegate = dataSourceHandlerDelegate;
    this.storefrontServiceHelper = storefrontServiceHelper;
 }
}

public class StorefrontServiceHelper {

    private final CatalogServiceHelper catalogServiceHelper

     public StorefrontServiceHelper(CatalogServiceHelper catalogServiceHelper){
    this.catalogServiceHelper = catalogServiceHelper;
   }

 }

public class CatalogServiceHelper {

   private final DataSourceHandler dataSourceHandlerDelegate

   public CatalogServiceHelper(DataSourceHandler dataSourceHandlerDelegate) {
    this.dataSourceHandlerDelegate = dataSourceHandlerDelegate
   }

 }

public interface DataSourceHandler {

}

public class DataSourceHandlerDelegate implements DataSourceHandler {

    public DataSourceHandlerDelegate(DataSourceHandler dynamoDBDataSourceHandler){
    this.dynamoDBDataSourceHandler = dynamoDBDataSourceHandler
   }
 }

 public class AppConfig {

 @Bean
 DataSourceHandlerDelegate 
 dataSourceHandlerDelegate(@Qualifier("DataSourceHandlerDelegate") DataSourceHandler 
 dynamoDBDataSourceHandler){
  return new DataSourceHandlerDelegate(dynamoDBDataSourceHandler)
}

Getting below run time error :

2024-10-26 16:20:31,703 [thread="main" class="o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext" cid="" id="" dd_trace_id="" dd_span_id=""] Exception encountered during context initialization cancelling refresh attempt: org.springframework.beans.factory. Unsatisfied Dependency Exception: Error creating bean with name 'catalogServiceImpl' defined in file [item-service/build/classes/java/main/com/item/grpc/CatalogServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory. UnsatisfiedDependencyException: Error creating bean with name 'storefrontServiceHelper' defined in file [item-service/build/classes/java/main/com/item/service/StorefrontServiceHelper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory. UnsatisfiedDependencyException: Error creating bean with name 'catalogServiceHelper' defined in file [item-service/build/classes/java/main/com/item/service/CatalogServiceHelper.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory. Unsatisfied DependencyException: Error creating bean with name 'dataSourceHandlerDelegate' defined in class path resource [com/item/config/AppConfig.class]: Unsatisfied dependency expressed through method 'dataSourceHandlerDelegate' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com..item.datasource.DataSourceHandler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation. Qualifier (value="DataSourceHandlerDelegate")}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video