Call @RequestScoped Bean from @PreDestroy Method

I have application logic for writing a log file to an @RequestScoped bean. I would like to write a protocol just before the @SessionScoped bean expires.

@SessionScoped class Anybean implements Serializable { @Inject private ProtocolBean protocolBean; @PreDestroy private void writeFinalProtocol() { protocolBean.writeProtocol(); } 

}

I get the error message: WELD-000019 Instance destruction error Managed bean. Is it generally forbidden to call other beans from @PreDestroy?

+4
source share
1 answer

OK I found out: As soon as I change ProtocolBean to @SessionScoped or @ApplicationScoped, everything works fine. It seems you cannot create an instance of RequestScoped bean using the @PreDestroy method and call the method on it.

A subclass exception is: com.sun.jdi.InvocationException method call occurred

+1
source

Source: https://habr.com/ru/post/1486651/


All Articles