1
votes

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.

5
How your Spring context is initialized, by xml or annotations? Make sure that JobService can be accessed via package scan - Alex Salauyou
It is pure annotation bused, no XML - Ayush Jain
u need to define by using @Config classes - MangduYogii
Remove @Service annotation from the IJobService. You only need to annotate the Implementation - Mehdi Benmesssaoud
add @Controller for JobSearchresource - MangduYogii

5 Answers

3
votes

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;
}
1
votes

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);
    }
}
0
votes

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

0
votes

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

-1
votes

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.