Ayush Jain
Ayush Jain

Reputation: 349

Getting error - No qualifying bean of type

I have an interface named IJobService

@Service
public interface IJobService {
    List<SearchTupleModel> getTuplesFromJobService(List<String> jobIds);
}

I have a class JobService implementing this:

@Service
public class JobService implements IJobService {
}

In a controller, I am just autowiring this interface as:

public class JobSearchResource {
    @Autowired
    IJobService iJobService;
}

But I am getting the error:

No qualifying bean of type e available: expected at least 1 bean which qualifies as autowire candidate.

Upvotes: 2

Views: 6053

Answers (5)

Mehdi Benmesssaoud
Mehdi Benmesssaoud

Reputation: 534

Remove @Service annotation from the Interface IJobService.

public interface JobService {
    List<SearchTupleModel> getTuplesFromJobService(List<String> jobIds);
}


@Service
public class JobServiceImpl implements JobService {
}

And add @Controller to your controller

@Controller
public class JobSearchResource {
   @Autowired
   JobService jobService;
}

Upvotes: 3

Prashant Sharma
Prashant Sharma

Reputation: 395

you should remove @Service annotation from the interface, also define your JobSearchResource bean using @Component or @Controller if its controller.

Upvotes: 0

Jagan Kornana
Jagan Kornana

Reputation: 171

Your project Application.java(or some other name) file which is containing the main method should be in the root directory as shown in the given reference:

sample spring boot project structure

Application.java file should contain the annotation @SpringBootApplication which will automatically scan all the files and create beans for them if they are annotated with @Service, @Controller, @Configuration etc...

Or else if you want to keep the Application.java file in some other package then you have to explicitly mention the root directory in the component scan annotation as shown below:

@SpringBootApplication
@ComponentScan(basePackages = {"com.starterkit.springboot.brs"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Upvotes: 1

MangduYogii
MangduYogii

Reputation: 985

expected at least 1 bean which qualifies as autowire candidate.

This class configure a spring bean

@Configuration
public class IJobServiceConfig {
   @Bean 
   public IJobService iJobService (){
       return new IJobService ();
   }
}

also Add @Controller for controller class

Upvotes: 0

g.momo
g.momo

Reputation: 566

Can you remove @Service above your interface IJobService ?

@Service indicates the code below is candidate for injection.

Since both IJobService and JobService have @Service, it yields 2 choices so spring does not know which one to use.

Upvotes: 0

Related Questions