Swagger UI 3: A quick setup guide with Spring Boot

Share this

Check out our previous blog on Swagger UI 2.x setup with Spring Boot application. In this blog, we will see how to do the same with the 3.xx version of Swagger UI 3.

How to do Swagger UI 3 setup with Spring Boot?

You can do Swagger UI 3 setup by following these simple steps in a Spring Boot application.

Step 1

  • Head to Spring Initializer.
  • Add “Spring Web” and “Spring Boot DevTools” in the dependency.
  • Fill up the project meta-data
  • Click on the “Generate” button

Step 2

  • Import the project in Eclipse or your favorite IDE
  • Open pom.xml and add these dependencies –
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-boot-starter</artifactId>
	<version>3.0.0</version>
</dependency>
  • With Swagger 3 you don’t need to add Docket configuration or use @EnableSwagger2 annotation. Everything is taken care of by Springfox-boot-starter, which we just added in the pom.xml above.

That’s It. done! Run the Spring Boot application main class and hit the below URL in the browser.

http://localhost:8080/swagger-ui/

Notice the change in the URL above. It doesn’t need to be swagger-ui.html now also note the ending forward-slash (“/”) at the end of the localhost URL.

Code available on Github – https://github.com/webfuse2017/wf-spring-poc/

In the above code example, there is a multipart file upload example in the controller code. It also has a small change to use

@RequestPart("file") MultipartFile file

instead of

@RequestParam("file") MultipartFile file

Feel free to share your viewpoints on this topic in the comments section below 🙂

Share this

Leave a comment

Your email address will not be published. Required fields are marked *

3 thoughts on “Swagger UI 3: A quick setup guide with Spring Boot”