Integrating JAX-RS + Jersey in Spring Boot Application

[Last Updated: Jul 13, 2018]

Instead of Spring MVC, Boot application can be integrated with one of the available JAX-RS implementations (e.g. Jersey, Apache CXF etc). In this example, we will see how to use Jersey. Following are the steps to achieve that:

  1. Add spring-boot-starter-jersey dependency.
  2. Register JAX-RS resource (annotated with JAX-RS annotation) as a bean.
  3. Register the resource class, created in step 2, with org.glassfish.jersey.server.ResourceConfig. The instance of ResourceConfig is itself needed to be registered as Spring bean.



<project .....>

The JAX-RS Resource Class

package com.logicbig.example;

import org.springframework.stereotype.Component;

public class MyJaxRsResource {


  public String getMessage(@PathParam("type") String type) {
      return "message from JAX-RS app for " + type;

Registering the JAX-RS resource

package com.logicbig.example;

import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

public class SpringBootMain {

  ResourceConfig resourceConfig() {
      return new ResourceConfig().register(MyJaxRsResource.class);

  public static void main(String[] args) {;


Running the main class from IDE and accessing the app from browser:

Example Project

Dependencies and Technologies Used:

  • Spring Boot 2.0.0.RELEASE
    Corresponding Spring Version 5.0.4.RELEASE
  • spring-boot-starter-jersey : Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web.
  • JDK 1.8
  • Maven 3.3.9

Integrating JAX-RS + Jersey in Spring Boot Select All Download
  • using-jax-rs-in-boot-app
    • src
      • main
        • java
          • com
            • logicbig
              • example

    See Also