2

Hi I am following this post Best practice for REST token-based authentication with JAX-RS and Jersey to implement a token based authentication system. When I am deploying the services, tomcat is getting started and not getting any error related auto-wiring or other, but when I am hitting a controller, I am not able to fire the event as it is showing null pointer exception for userAuthenticatedEvent. I think the event is not initialized.

@Autowired
@AuthenticatedUser
private Event<Long> userAuthenticatedEvent;
manish
  • 53
  • 7

1 Answers1

0

You need to use @Inject over the declaration. The Event<T> class from javax.enterprise.event is managed and instantiated automatically by CDI. When you need to fire the event just use fire() passing an argument of type T in it. eg:

@Inject
@AuthenticatedUser
private Event<Long> userAuthenticatedEvent;

userAuthenticatedEvent.fire(*some Long value*);