In this article we are going to see how simple and fast it is to add swagger UI in SpringBoot project.
What is Swagger?
As per Google: “Swagger is an Interface Description Language for describing RESTful APIs expressed using JSON. Swagger is used together with a set of open-source software tools to design, build, document, and use RESTful web services. Swagger includes automated documentation, code generation (into many programming languages), and test-case generation.”
Prerequisites
- Must have a basic SpringBoot project up and running. (Click here to see how)
Table of Content
- Adding Swagger Dependencies
- Enabling Swagger in your SpringBoot Project
STEP 1: Adding Swagger Dependencies
In the first place, to integrate swagger to your SpringBoot project, you need to add the following dependencies in the POM.xml file of your project.
io.springfox
springfox-swagger2
2.6.1
compile
io.springfox
springfox-swagger-ui
2.6.1
compile
STEP 2: Enable Swagger in your SpringBoot Project
After adding all the dependencies, we now need to add an annotation to add swagger UI in the SpringBoot project. Simply open up your entry point java class and add this annotation at the top: “@EnableSwagger2”.
Next, you need to add a Bean instance inside the same class where you added the above annotation. Therefore, copy the following code in your main java application entry class.
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.java_crud_api_mysql"))
.build();
}
Take reference from the image shown below.
In the code that you will add, it asks for a ‘base package’. This is going to be the package name that is mentioned at the very top of the same java class. It’s also highlighted with a red box in the above image as well. This bean instance basically tells the swagger to find all the available API endpoints in all your controller classes of your project. And then it will be displayed to the user on the browser at a specific URL. This project is running on port 8080, so the URL is going to be http://localhost:8080/swagger-ui.html
Finally, run the project and go the above-mentioned URL and you will be displayed with the Swagger UI like so:
And we are done!
Hope this helps you to understand how exactly to add Swagger UI in the SpringBoot project. If you have any questions, please leave a comment down below and share this article with others too.
Have a great one!
Recent Posts
- Казино Официальный Сайт Играть в Онлайн Казино Pin Up.2324
- Embrace the Spin Elevate Your Play with Captivating online casino slots & Unforgettable Jackpots.
- Elevate Your Play – Explore a Universe of Thrills with online casino slots and Claim Lucrative Rewar
- Hospitalier et attractif, le monde d’alexander casino vous attend
- Elevate Your Play with 30+ Payment Options & €1200 Bonus – Find Your Fortune at sky crown casino log
Recent Comments
Archives
- May 2026
- October 2025
- August 2025
- June 2025
- October 2024
- September 2024
- August 2024
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- Angular
- AWS
- Backend Development
- Big Data
- Blog
- Casino
- Cloud
- Database
- Deployment
- DevOps
- Docker
- Frontend Development
- GitHub
- Google Cloud Platform
- Installations
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- NodeJS
- Online casino
- Operating System
- Post
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
Search
Recent Post
Казино Официальный Сайт Играть в Онлайн Казино
- 19 May, 2026
- 1 min read
Embrace the Spin Elevate Your Play with
- 19 May, 2026
- 5 min read
Elevate Your Play – Explore a Universe
- 19 May, 2026
- 6 min read