OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.16k stars 597 forks source link

Datasource injection using @Resource does not work in JAX-RS resource #6120

Open awisniew90 opened 5 years ago

awisniew90 commented 5 years ago

Injecting a datasource using the @Resource annotation does not work with a plain JAX-RS resource (with @PATH annotation). A NPE is thrown on the datasource object.

This works when the @ApplicationScoped annotation is added to the JAX-RS class and the cdi-2.0 feature is enabled on the server.

This may be a bug, or this may just be a path that is not supported.

I've attached a sample app demonstrating the failure. Just run mvn clean install to build and deploy.

awisniew90 commented 5 years ago

test-jaxrs-2.1.zip

scottkurz commented 5 years ago

Not really sure how the CDI introspection intersects the web/ejb container introspection for something like this. It could very well be the latter here not CDI which is relevant... but, if so, I assume the CDI team can reassign. Thanks.

scottkurz commented 5 years ago

This is with feature set:

    <featureManager>
        <feature>jdbc-4.1</feature>
        <feature>jaxrs-2.1</feature>
    </featureManager>

with code snippet:

@Path("/hello")
public class HelloResource {

    @Resource
    DataSource ds1;

Adding JAX-RS label in case it helps get attention.

andymc12 commented 2 years ago

Is this still an issue? We have made changes in the resource injection space for JAX-RS components, so I think it's possible that this may already be resolved.