Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If the Apache CXF application contains only either no instance of JAX-RS Application or only one single instance of JAX-RS Application (annotated with @ApplicationPath) with no singletons and classes defined, the following rules are being applied by JAXRSCdiResourceExtension in order to configure and publish the configured JAX-RS resources:

...

Code Block
java
java
@Path("/bookstore/")
public class BookStore {
    @Inject private BookStoreService service;
    
    @GET
    @Path("/books/{bookId}")
    @Produces(MediaType.APPLICATION_JSON)
    public Book getBook(@PathParam("bookId") String id) {
        return service.get(id);
    }
}

Additional Configuration Capabilities

If you have a need to, you can configure the underlying JAXRSServerFactoryBean by implementing the interface JAXRSServerFactoryCustomizationExtension.  Instances of this extension can be located via ServiceLoader of as CDI beans.  You can use this to programmatically add new providers, or otherwise manipulate the runtime before the server is created.  An example of how this is used can be seen at SseTransportCustomizationExtension.

CDi Lifecycle for JAX-RS Context Objects

The CDI extension also supports the injection (via CDI) of @Context objects.  Any known object can be injected via CDI.  This happens automatically when the CDI extension is used, and a @Context is declared as a field on a resource class.  Note that this does allow you to inject your @Context objects in non-JAX-RS components as well.  The logic is in two parts:

  1. Rewriting injection points
    1. When an injection point is found that contains @Context two additional annotations are added
    2. These annotations are @Inject and @ContextResolved
    3. The use of @Inject will force the CDI runtime to take over the injection of the bean value, while @ContextResolved is simply a qualifier we apply to the injection point to avoid ambiguities
  2. Providing Beans
    1. For each of the built in @Context types, we register a bean that provides a @RequestScoped bean that resolves the value, by looking up the internal context value
    2. In addition, a user or intergrator can implement ContextClassProvider to register an additional class as context type to be resolved.

 

Deploying with embedded Jetty 8/9 (programmatic configuration)

...