...
At the moment, the integration of Apache CXF and CDI revolves around two key components, residing in new module called cxf-integration-cdi
...
- CXFCdiServlet servlet
...
- JAXRSCdiResourceExtension portable CDI extension
The fact of including cxf-integration-cdi as a dependency allows JAXRSCdiResourceExtension portable CDI extension to be discovered by CDI container. The JAXRSCdiResourceExtension creates the instance of the Bus and registers it with BeanManager. From this point, the Bus instance is a regular CDI bean (with @Application scope) available for injection. This instance of the Bus is being injected into CXFCdiServlet servlet once it is initialized by servlet container.
...
From this moment, Apache CXF application is ready to serve the requests. The quick example is shown below.
...
The configured JAX-RS Application:
Code Block | ||||
---|---|---|---|---|
| ||||
@ApplicationPath("/custom")
public class BookStoreCustomApplication extends Application {
@Inject private BookStore bookStore;
@Override
public Set< Object > getSingletons() {
return Sets.< Object >newHashSet(
bookStore,
new JacksonJsonProvider(),
new ValidationExceptionMapper(),
new JAXRSBeanValidationFeature());
}
} |
And one JAX-RS resource:
Code Block | ||||
---|---|---|---|---|
| ||||
@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);
}
} |