Micronaut JAX-RS

JAX-RS Support for Micronaut

Version:

1 Introduction

Micronaut JAX-RS adds support for using JAX-RS annotations and types in a Micronaut application with the aim of helping migrate existing JAX-RS applications or support teams her prefer the JAX-RS annotations.

This project is not an implementation of the JAX-RS specification and is designed to allow users familiar with the JAX-RS API to use the most common parts of the API within the context of a Micronaut application.

2 Quick Start

To use this project you need Micronaut 1.3 or above then add the following annotation processor to any Micronaut project:

annotationProcessor("io.micronaut.jaxrs:micronaut-jaxrs-processor:1.0.0")
<annotationProcessorPaths>
    <path>
        <groupId>io.micronaut.jaxrs</groupId>
        <artifactId>micronaut-jaxrs-processor</artifactId>
        <version>1.0.0</version>
    </path>
</annotationProcessorPaths>

Then the following compile time dependency:

implementation("io.micronaut.jaxrs:micronaut-jaxrs-server:1.0.0")
<dependency>
    <groupId>io.micronaut.jaxrs</groupId>
    <artifactId>micronaut-jaxrs-server</artifactId>
    <version>1.0.0</version>
</dependency>

3 Supported API

As of this writing Micronaut JAX-RS supports the annotations and types defined within the javax.ws.rs package and the javax.ws.rs.core subpackage only.

All interfaces, annotations and types contained within the following packages are not supported:

  • javax.ws.rs.client

  • javax.ws.rs.container

  • javax.ws.rs.ext

Supported Annotations

Micronaut JAX-RS works by converting (at compilation time) a JAX-RS annotation definition into the equivalent Micronaut version.

Table 1. Supported JAX-RS Annotations
JAX-RS Annotation Target Annotation Example

@Path

@Controller

@Path("/foo") // on type

@Path

@UriMapping

@Path("/foo") // on method

@HttpMethod

@HttpMethodMapping

@HttpMethod("TRACE")

@GET

@Get

@GET @Path("/foo/bar")

@POST

@Post

@POST @Path("/foo/bar")

@DELETE

@Delete

@DELETE @Path("/foo/bar")

@OPTIONS

@Options

@OPTIONS @Path("/foo/bar")

@HEAD

@Head

@HEAD @Path("/foo/bar")

@Consumes

@Consumes

@Consumes("application/json")

@Produces

@Produces

@Produces("application/json")

@PathParam

@PathVariable

@PathParam("foo")

@CookieParam

@CookieValue

@CookieParam("myCookie")

@HeaderParam

@Header

@HeaderParam("Content-Type")

@QueryParam

@QueryValue

@QueryParam("myParam")

@DefaultValue

@Bindable(defaultValue="..")

@DefaultValue("example")

@Context

No equivalent. Injects a bean in to a parameter.

@Context

Injectable Parameter Types

In addition to the supported JAX-RS annotations you can use the following JAX-RS types as parameter types to resources or client definitions:

You can also use the @Context annotation to inject any bean into a resource type’s method parameter.

Parameter binding to constructor argument of resource types is not supported at this time.

Supported Return Types

You can also use the following return types from the JAX-RS API in your resource classes:

4 Repository

You can find the source code of this project in this repository: