I am creating a Springboot project in which I have two service interfaces whom I am injecting in my Controller
StudentService
JavaScript
x
public interface StudentService {
void addStudent(Student student);
//other functions
}
TeacherService
JavaScript
public interface TeacherService {
void addStudent(Teacher teacher);
//other functions
}
When I am using @Autowired for the StudentService it is working fine but I am getting an error when I am using @Autowired for the TeacherService in my Controller.I try alot but did not find the cause of the error.
My Controllers
JavaScript
@Controller
public class StudentController {
@Autowired
StudenService studenService;
.
.
}
JavaScript
@Controller
public class TeacherController {
@Autowired
TeacherService teacherService;
.
.
}
Advertisement
Answer
This type of error generally happens when you might have not used @Service at your Service implementation or The service interface has not been implemented yet. So be sure that you have implemented your Service interface and it should be annotated with @Service.
JavaScript
@Service
public class TeacherServiceImp implements TeacherService {
//your codes
}