How to set up Spring Boot app documentation with Springfox

Learn how to generate documentation for your Spring Boot application using Springfox Boot Starter. This article extends the Spring Boot API documentation with Swagger post.

In order to see an example Spring Boot project where the starter replaced the older Springfox version, visit the 951ba8dc0fd805c21daf8a483ab730b19f30677f commit.

Add Springfox Boot starter

First, add the maven dependency to your pom.xml file:

Second, create a class where we’re going to configure Swagger docs, like in my example SwaggerConfig.java file from the scrum_ally project:

Finally, we have to configure handling resources. You’ll find the example config from the Springfox documentation below:

The scrum_ally project uses Angular, so the its configuration is a little bit different, you can find it in the MvcConfiguration file.

In the end, we can finally start our app and see the documentation. We should be able to get the project specification in json by calling the http://localhost:8080/v3/api-docs endpoint (example in Postman):

swagger specification in json generated by springfox for our spring boot project

Furthermore, we also can see the documentation in Swagger UI on http://localhost:8080/swagger-ui/:

documentation in swagger ui

Adjust the security config

In order to allow all GET requests to the documentation resources when your project uses Spring Boot security starter, add this matcher to your config:

Useful links

Photo by Andrea Piacquadio from Pexels

Leave a Reply

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