Configure Swagger With Jersey and Spring Boot


Author - FrugalisMinds

Configure Swagger With Jersey and Spring Boot:-

We are going to configure Swagger With Jersey and Spring Boot. We saw applications are moving towards micro-services architecture. one of the important aspects of API development is API documentation. Great documentation results in proper experience in API consumption. We are going to use and Configure Swagger and Swagger UI for API documentation along with Jersey and Spring Boot.

Swagger is Used for standardizing API documentation and provide a consistent specification. Swagger UI  helps in visualizing and interact with our API's.

Integration of Spring with Swagger is a straightforward task with  Spring provided annotations. Using Spring Boot Swagger with JAX-RS is a bit tricky task. Let's continue and create a  Spring Boot Jersey Project referring our post Spring Boot Jersey Example.

Project Dependencies:-

  1. Spring Boot
  2. swagger-jersey2-jaxrs
  3. spring-boot-starter-web

Here is our pom.xml with spring boot swagger maven dependency and other required dependencies.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


	<description>Demo project for Spring Boot</description>

		<relativePath /> <!-- lookup parent from repository -->








Configuration Of Swagger and Jersey:-

Now we have already added swagger maven dependencies, now it's the time to configure swagger with jersey and spring boot. Lets  add a swagger configuration in our Jersey Config as below.

package com.frugalis.SpringBootJersey;

import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
import io.swagger.jaxrs.listing.SwaggerSerializers;

import javax.annotation.PostConstruct;

import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JerseyConfig extends ResourceConfig {

	public JerseyConfig(ObjectMapper objectMapper) {
		register(new ObjectMapperContextResolver(objectMapper));

	public static class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
		private final ObjectMapper mapper;
		public ObjectMapperContextResolver(ObjectMapper mapper) {
			this.mapper = mapper;

		public ObjectMapper getContext(Class<?> type) {
			return mapper;
	  public void init() {
	    // Register components where DI is needed
	private void SwaggerConfig() {
	    BeanConfig swaggerConfigBean = new BeanConfig();
	    swaggerConfigBean.setConfigId("Frugalis Swagger Jersey Example");
	    swaggerConfigBean.setTitle("Using Swagger ,Jersey And Spring Boot ");
	    swaggerConfigBean.setSchemes(new String\[\] { "http", "https" });

We are setting basepath asswaggerConfigBean.setBasePath("/api") this path could be anything. On successful setup, we can check our swagger setup is working or not by going to http://localhost:8080/api/swagger.json

Once we get an output JSON as response, our first step to Configure Swagger With Jersey and Spring Boot is Done.

Now the next step is Configuring Swagger UI.

Note:-   Visit this Site to Understand More about Basics Of Java and Collections.

Some Must Read Posts

  1. React JS Tutorials
  2. Spring Boot Jersey Example
  3. CRUD Rest API With Spring Web-Flux Reactive Programming with Spring 5
  4. Creating REST Service with Spring Boot
  5. CRUD Rest Service With Spring Boot and JPA
  6. Spring Boot Profiling – Configure for Different Environments

Configure and Setup Swagger UI:-

Visit Swagger UI GitHub project and download dist version of the Project. Extract contents and move the dist content to **/src/main/resources/static** , we can create the folder structure if it is not present. The dist folder under the GitHub project contains  JavaScript, CSS, images and HTML files used for swagger UI.

We need to update **index.html**inside for**src/main/resources/static/index.html** Swagger UI to find the configuration and load the UI accordingly. Replace text with**** to your  **swagger**.**json** URL. In this case, our swagger.json is located at **http://localhost:8080/api/swagger.json**

    window.onload = function() {

      // Build a system
      const ui = SwaggerUIBundle({
        url: "api/swagger.json",
        dom\_id: '#swagger-ui',
        deepLinking: true,
        presets: \[
        plugins: \[
        layout: "StandaloneLayout"

      window.ui = ui


Swagger Spring Boot and Jersey [sociallocker id="1183"]