0

The Spring event mechanism supports publishing application events and listening to these events. as it is explained in this question: Scoped Spring events possible? spring event notify only the current request session listeners. so my question is that possible to notify all existent scoped beans.

code example:

@Controller
public class FooController {

@Autowired
private ApplicationEventPublisher publisher;

@GetMapping("/fireEvent")
public void notifyAllScopedBeans() {
    publisher.publishEvent(new FooEvent(this));
 }
}



@SessionScope
@Component
public class FooListener {
private String username = "this bean username"
@EventListener(FooEvent.class)
public void listen() {
     System.out.println("I'm listening. PS : I am 
    "+this.username);
 }
}
kimo815
  • 33
  • 7
  • No it isn't... If it would it would mean anyone could access and modify the `HttpSession` and that would be quite a security risk. – M. Deinum Jan 09 '19 at 11:27
  • in my case the responsible of firing the vent is third party server who send real time data and spring must notify all connected users. – kimo815 Jan 09 '19 at 11:38
  • You cannot with a session scoped listener. You could with web sockets. – M. Deinum Jan 09 '19 at 11:48
  • i didn't understand can you explain more please. – kimo815 Jan 09 '19 at 13:10
  • What isn't clear. If you want something like that you need to use web sockets... Using session scoped application listeners won't work as you cannot access someone else session. – M. Deinum Jan 09 '19 at 13:10
  • can you explain how to do that with web-socket or giving me some useful link and thank you. – kimo815 Jan 09 '19 at 13:17

0 Answers0