I have to inject initApplicationContext bean on ContextCacheRefresh web service, but unsuccessful, initApplicationContext value always is null. Have anybody any idea haw to deal with it?
@ManagedBean(name = "initApplicationContext", eager = true)
@ApplicationScoped
public class InitApplicationContext {
.......................
}
and web service
@Path("/serviceContext")
public class ContextCacheRefresh {
@ManagedProperty(value = "#{initApplicationContext}")
private InitApplicationContext initApplicationContext;
@GET
@Path("/refreshContext")
public Response refreshUserListOn(@QueryParam("param") String param
) { ......
You'll not be able to get JSF to inject resources into a non-JSF context, using @ManagedProperty. Your options are
Convert your managed bean to use CDI annotations (@Named to declare the managed bean and @Inject instead of the JSF annotations you're working with now.
Just pull the bean from the plain servlet context using the following:
//inject the servlet context
@javax.ws.rs.core.Context
ServletContext servletContext
public InitApplicationContext getInitContext(){
return (InitApplicationContext)servletContext.getAttribute("initApplicationContext");
}
What you're working toward seems a bit dodgy to me. Why is your web application concerned with your RESTful endpoint to begin with?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With