java ee - JAX-RS: Custom class object no injected into a ContainerRequestFilter -


i've created containerrequestfilter implementation this:

@provider @prematching @secured @dependent public class bearerfilter implements containerrequestfilter {      @inject protected memcachedapplicationresources memcachedresources;      @override     public void filter(containerrequestcontext requestcontext) throws ioexception     {         //this.memcachedresources null here.     } } 

as can see i'm trying inject memcachedapplicationresources object memcachedresources field.

memcachedapplicationresources like:

@applicationscoped public class memcachedapplicationresources {} 

why null?

edit

i've created beans.xml file content:

<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">  </beans> 

however, it's still null.

enter image description here

edit 2

i've tried create filter instead of containerrequestfilter:

@webfilter(     dispatchertypes = {dispatchertype.request },     urlpatterns = { "/cmng/*" },     initparams = { @webinitparam(name = "excludedpaths", value = "log") }     ) public class bearerwebfilter implements filter {      @inject protected memcachedresources memcachedresources;      public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception     {         //here, this.memcachedresources injected proxy!     } } 

why using filter class field injected?

the injection should work if:

  • you have beans.xml file under web-inf (not mandatory cdi 1.2).
  • your filter bean managed cdi.

depending on container, may require dependency make cdi works resteasy, should work out-of-the-box wildfly. see documentation more details.


if doesn't work, still can try instance programmaticaly using:

memcachedapplicationresources bean =      cdi.current().select(memcachedapplicationresources.class).ge‌​t(); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -