I have a bean in my spring boot application as follows:
@Component
public class DatabaseStudentLoader {
private final StudentRepository studentRepository;
private final Map<String, Student>> idToStudentEntityMap;
/**
* Instantiates a new Database loader.
*
* @param studentRepository the student repository
*/
public DatabaseStudentLoader(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
public void doSomeOperation() {
//here I am constructing the map, reading entities from DB
...
}
}
Here, I would like the above bean with the map to be refreshed as soon as an entity gets updated/deleted/created in my MySQL DB.