i’m developing a websocket, and i created an entity listener that after un update on a table must alert the websocket.
In doing so, i need a value that i should retrieve from the db, but since in entity listeners methods i should not do query, in this project we already implemented a cache system, where the value i need is actually stored.
So, i’m autowiring in the entity listener this CacheService class, but i always get the NullPointerException. Also, i need to autowire the Handler of the WebSocket, i need to use it to send the message to every session.
I already read all the topics here, but none could help me.
I tried annotating the EntityListener class with @Component, but nothing. Also, i made the class extend SpringBeanAutowiringSupport, but also didn’t work.
@Component
public class EListener extends SpringBeanAutowiringSupport {
@Autowired
private LockHandler handler;
@Autowired
private CacheService cacheService;
@PostUpdate
private void afterUpdate(Elab elab){
final DSTate state1 = cacheService.getAllStates().stream()
.filter(x -> x.getId().equals(elab.getFkState())).findFirst().orElse(new DState());
handler.sendMessage(state1);
I did a lot of researches about this, but the last questions are from 3-4 years ago, so maybe now there’s a better way of implementing this.