I have a controller
@Controller
public class AppController{
@Autowired
private IDemoApplicationService service;
//more code
}
Service
@Service("service")
public class DemoApplicationServiceImpl implements IDemoApplicationService{
@Override
public void createEmployee(Employee employee){
try {
dao.insertEmployee(employee);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public String updateEmployee(Employee employee, int id) {
dao.updateEmployee(employee, id);
return "redirect:/employees";
}
@Override
public String deleteEmployee(int id) {
dao.deleteEmployee(id);
return "redirect:/employees";
}
@Override
public String getEmployees(Model model) {
model.addAttribute("employees", dao.getEmployees());
return "employees";
}
@Override
public Employee findById(int id) {
return dao.findById(id);
}
}
Service Interface
public interface IDemoApplicationService {
}
I want to use @Autowired in my controller to use the service but when I run the application I get the following error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private services.IDemoApplicationService controllers.DemoApplication.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [services.IDemoApplicationService] 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)}
Can anyone tell me what should I do to make it work?
Thanks
@SpringBootApplication
? - Makoto