tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Kaltepoth (JIRA)" <j...@apache.org>
Subject [jira] [Created] (TOMEE-2122) CDI injection into dynamically registered JAX-RS providers fails
Date Thu, 31 Aug 2017 15:56:01 GMT
Christian Kaltepoth created TOMEE-2122:
------------------------------------------

             Summary: CDI injection into dynamically registered JAX-RS providers fails
                 Key: TOMEE-2122
                 URL: https://issues.apache.org/jira/browse/TOMEE-2122
             Project: TomEE
          Issue Type: Bug
    Affects Versions: 7.0.2
         Environment: JDK 1.8.0_141-b16, Apache Tomcat (TomEE)/8.5.6 (7.0.2)
            Reporter: Christian Kaltepoth


If JAX-RS providers are registered dynamically using a {{Feature}}, CDI injection into the
provider doesn't work.

If you for example annotate a {{ContainerRequestFilter}} with {{@Provider}}, injection works

fine!

{code:java}
@Provider
public class MyFilter implements ContainerRequestFilter {

    @Inject
    private SomeBean someBean;

    @Override
    public void filter(ContainerRequestContext containerRequestContext) throws IOException
{

        System.out.println("Injected: " + someBean);   // injection works fine!!!

    }
}
{code}

Now remove the {{@Provider}} annotation and add a {{Feature}} which registers the provider:

{code:java}
@Provider
public class MyFeature implements Feature {

    @Override
    public boolean configure(FeatureContext featureContext) {
        featureContext.register(MyFilter.class);
        return true;
    }

}

public class MyFilter implements ContainerRequestFilter {

    @Inject
    private SomeBean someBean;

    @Override
    public void filter(ContainerRequestContext containerRequestContext) throws IOException
{

        System.out.println("Injected: " + someBean);   // NULL

    }
}
{code}

In this case injection does not work at all!



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message