0
0
Spring Bootframework~30 mins

Swagger UI integration in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Swagger UI integration
📖 Scenario: You are building a Spring Boot REST API for a simple product catalog. You want to add Swagger UI to your project so that anyone can easily see and test your API endpoints in a friendly web interface.
🎯 Goal: Integrate Swagger UI into your Spring Boot project so that the API documentation is automatically generated and accessible via a web browser.
📋 What You'll Learn
Add the Swagger dependencies to your project
Create a Swagger configuration class
Configure Swagger to scan your REST controllers
Access the Swagger UI page in the browser
💡 Why This Matters
🌍 Real World
Swagger UI helps developers and testers explore and try out REST APIs easily without writing extra code.
💼 Career
Many companies use Swagger/OpenAPI to document APIs clearly, making this skill valuable for backend and full-stack developers.
Progress0 / 4 steps
1
Add Swagger dependencies
Add the following dependency to your pom.xml file inside the <dependencies> section: <dependency>\n <groupId>io.springfox</groupId>\n <artifactId>springfox-boot-starter</artifactId>\n <version>3.0.0</version>\n</dependency>
Spring Boot
Need a hint?

Make sure to add the dependency inside the <dependencies> tag in your pom.xml.

2
Create Swagger configuration class
Create a Java class named SwaggerConfig in your project under package com.example.config. Annotate it with @Configuration and @EnableOpenApi. Import these annotations from springfox.documentation.oas.annotations.EnableOpenApi and org.springframework.context.annotation.Configuration.
Spring Boot
Need a hint?

This class enables Swagger OpenAPI support in your Spring Boot app.

3
Configure Swagger Docket bean
Inside the SwaggerConfig class, add a public method named api that returns a Docket object. Annotate it with @Bean. In the method, return a new Docket with DocumentationType.OAS_30, and configure it to select any APIs and any paths using select(), apis(RequestHandlerSelectors.any()), and paths(PathSelectors.any()). Import necessary classes from springfox.documentation.spring.web.plugins.Docket, springfox.documentation.spi.DocumentationType, springfox.documentation.builders.PathSelectors, and springfox.documentation.builders.RequestHandlerSelectors.
Spring Boot
Need a hint?

This method tells Swagger to document all API endpoints in your project.

4
Access Swagger UI in browser
Run your Spring Boot application. Open a web browser and go to http://localhost:8080/swagger-ui/index.html to see the Swagger UI page with your API documentation.
Spring Boot
Need a hint?

Make sure your Spring Boot app is running on port 8080 (default) before opening the URL.