i need an event listener, that has a condition bounded to a field of the parent bean. The bean is scoped as prototype & the field i want the listener to use in the condition is set via setter once a repeatedTasksExecutor instance is created:
@Component
@Scope("prototype")
public class RepeatedTasksExecutor implements Runnable, ApplicationListener<CustomEvent> {
String gameId;
public String getGameId() {
return gameId;
}
public void setGameId(String gameId) {
this.gameId = gameId;
}
//here i want to access the gameId field, that is set globally once the RepeatedTasksExecutor instance is initialized
@EventListener(condition = "@gameId == #event.gameId")
public void handleReturnedEvent(CustomEvent event) {
System.out.println("gameid: "+ event.getGameId());
}
}
From the documentation i have seen, that its possible to access a constant, but i can not use that, because in every instance the field has another value.
Any ideas here?