CDI-Injection is JAX-RS 2.1 (Java EE 8) Subresources

A JAX-RS subresource:

public class SubResource {

    Facade facade;

    public String sub() {
        return this.facade.sub();
with injected @Stateless "business logic":

public class Facade {

    public String root() {
        return "root";

    public String sub() {
        return "sub";

and exposed via a root resource:
import javax.inject.Inject;

public class RootResource {

    ResourceContext context;

    public SubResource sub() {
        return this.context.getResource(SubResource.class);
supports CDI injection in WildFly 15+, OpenLiberty, Payara 5+ as "nice to have" feature.

A curl invocation curl -i http://localhost:[PORT]/subresource-cdi-di/resources/root/sub returns: "sub".

The JAX-RS 2.1 spec states in 11.2.3 Context and Dependency Injection (CDI):

"In a product that supports CDI, implementations MUST support the use of CDI-style Beans as root resource classes, providers and Application subclasses.(...)"

Therefore the beviour of TomEE 8 (microprofile-8.0.0-M1) is correct by throwing:

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    

Deployed to multiple application servers simultaneously with: WAD

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments