In CDI bean passivation capabilities, is it possible for passivation-dependent dependencies to be re-injected rather than passivated?
In CDI bean passivation capabilities, is it possible for passivation dependent dependencies to be re-injected rather than passivated?
Consider this code:
@SessionScoped
public class UserData implements Serializable {
@Inject
private Logger log;
private String data;
}
@ApplicationScoped
public class LoggerFactory {
@Produces
public Logger getLogger(){
...
}
}
public class Logger {
...
}
So, Logger
not Serializable
, but I don't care. When UserData
deserialized, is it possible to extend for the Logger
call somehow?
EDIT
The initial discussion started here:
http://www.cdi-spec.org/news/2015/07/03/CDI-2_0-EDR1-released/#comment-2119769909
Hoping that the CDI panel of experts is better suited than @Instance
source to share
Checking the spec you have your answer. Logger
is not serializable, so the type bean is Logger
not passivable. The container does not provide the trick you are asking for.
The solution would be to write something like this:
@SessionScoped
public class UserData implements Serializable {
@Inject
private Instance<Logger> logInstance;
private String data;
public Logger getLog() {
return logInstance.get();
}
}
Ans is used getLog()
instead log
in your code.
source to share