Page 1 of 2
Swagger2 For SpringBoot
Swagger is an open source project used to
generate the REST API documents for restful
Web services.It provides a user interface to
access our RESTful web services via the web
browser
Steps to add and con gure swagger2 for Springboot
project:-
1.Add Maven Dependencies
If you are using maven then add the following swagger
dependencies in your pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.De ne SwaggerCon g.java
Create SwaggerCon g class to add swagger in the spring boot project,
below is the sample swagger con guration for RiskMonitoring project
fi
fi
fi
fi
fi
Page 2 of 2
• @Configuration annotation is used to auto scan this
class le.
• @EnableSwagger2 annotation is used to help Spring boot
project to add necessary dependency for Swagger
3.Verify Swagger.
Now de ne some controllers to expose REST api endpoints and
start your spring boot application.
fi
fi