Sample to config Swagger 2 with Spring MVC 4 and Spring Boot 2
Add Swagger 2 for Spring MVC
- Spring MVC version: 4.2.7
- Swagger version: 2.7.0
Add swagger2 dependency into pom.xml.
If using fastjson, must use the version greater then 1.2.15, as not support swagger 2 json below that version. Use jackson is safe.
Add Spring configuration.
Then we need create Swagger config class.
And then add it into bean context.
If the api-docs too big, swagger ui will have problem to render, so need to use path grouping to split the documents
1 |
|
Add Swagger 2 for Spring Boot
- Spring Boot version: 2.0.3
- Swagger version: 2.8.0
Similar with Spring MVC, we need add dependency libararies and config the swagger
Add swagger2 dependency into pom.xml.
1 |
|
Then we need create Swagger config class.
1 |
|
Verify the result
After success start the service, and you can verity the resuts via http://localhost:8080/v2/api-docs, or use the swagger ui http://localhost:8080/swagger-ui.html