How to inject the JAX-RS resources instance using interfaces

Solution Verified - Updated -

Issue

  • How to inject the JAX-RS resources using interfaces?
  • Executing the following code will throw javax.enterprise.inject.UnsatisfiedResolutionException. Is there a workaround for this issue?
public interface Greeting {
    public String hello();
}


@Path("/hello")
public class GreetingResource implements Greeting {

    @Inject
    InjectorService injectorService;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        injectorService.test();
        return "hello";
    }
}

@ApplicationScoped
public class InjectorService {
    @Inject
    Instance<Greeting> greeting;

    public void test() {
        // Runtime error:
        // javax.enterprise.inject.UnsatisfiedResolutionException:
        // No bean found for required type [interface org.acme.quickstart.Greeting] and qualifiers [[@javax.enterprise.inject.Default()]]
        System.out.println(greeting.get().hello());
    }
}

Environment

  • Red Hat Build of Quarkus (RHBQ)
    • 1.7.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content