I am using MVC design pattern for my project, I have an interface called SchoolRepository and I have a controller class where I have declared the school repository interface, I have declared the school repository interface in model class as well, when I invoke the model class object where I have written the logic from the controller I am getting null pointer exception as the school interface declared in service class is null
below is my controller class
@RestController
@RequestMapping("University")
public class Controller{
//interface declaration
@Autowired
SchoolRepository schoolRepository;
@GetMapping("student")
public list getStudent(){
Service s=new Service();
List list=s.getStudents();
return list;
}
.
.
}
below is my model class
public class Service(){
@Autowired
SchoolRepository schoolRepository;
public List getStudents(){
return schoolRepository.getAll();
}
below is the repository class
@Repository
public interface SchoolRepository extends JpaRepository<School, Long>{}
I get a null point exception in the Service class where I use schoolRepository, when I check the value of s.schoolRepository using System.Out.Println I get null value.. how to initialize the interface and how to use it in service class