0

I heav the following bean

@RequestScoped public class MyJWT {

@Inject
JsonWebToken jwt;

private User loggedUser;
private String rawToken;

@PostConstruct
public void init() {
    if (jwt != null && jwt.getRawToken() != null) {
        this.loggedUser = User.findByEmail( jwt.getClaim(Claims.email.name()).toString());
        this.rawToken = jwt.getRawToken();
    }
}

but I don't see init is called ever. I mean, my debugger doesn't stop on any breakpoints inside. In case debugger is confused by instrumentation, I was also trying to add exception throwing inside, but didn't see any effect.

How is this possible?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • How is this `MyJWT` class used? If noone calls any method on that bean, it won't be initialized. Keep in mind that for `@RequestScoped` beans, the container will inject a proxy, which will lookup (or create, for the first time) the instance corresponding to the "current" request _whenever a method is called_. – Ladicek Jan 22 '21 at 15:57
  • Methods are called, but can't change fields as if the class is reinitialized. – Suzan Cioc Jan 22 '21 at 16:06
  • I mean methods are definitely called and I am tracing them. – Suzan Cioc Jan 22 '21 at 16:06
  • OK, but how is the class used? You don't do `new MyJWT()`, right? (Sorry if that sounds like a dumb question, I've seen people doing that mistake way too often.) – Ladicek Jan 22 '21 at 16:30
  • No, Qaurkus ititializes it somehow, but probably lifetime is not the one I expect. – Suzan Cioc Jan 22 '21 at 16:54
  • Alright, that all sounds OK, so at this point, I don't know what could be the problem. Do you perhaps have a minimal but complete reproducer somewhere? – Ladicek Jan 22 '21 at 19:29

0 Answers0