Skip to content
Advertisement

Getting error while using @Autowired in the springboot

I am creating a Springboot project in which I have two service interfaces whom I am injecting in my Controller

StudentService

public interface StudentService {

    void addStudent(Student student);
    //other functions
}

TeacherService

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

@Controller
public class StudentController {

    @Autowired
    StudenService studenService;
    ....
    ....
}

@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.

@Service
public class TeacherServiceImp implements TeacherService {
//your codes
}

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement