In Java programming, “Swagger” typically refers to the Swagger API documentation tool, which is used to document and test RESTful web services. Swagger provides an interface which allows to understand capabilities of service without accessing its source code. Its often used to document and design RESTful APIs.
Add below code to pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
And then create java file with name SwaggerConfig.java
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket techByBugApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("controller package"))
.build()
.apiInfo(metaData());
}
private ApiInfo metaData() {
ApiInfo apiInfo = new ApiInfo(
"Spring REST API",
"Spring Boot REST API ", "1.0","Terms of service",
new Contact("name", "AppName", "message"),
"Apache License Version 2.0",
"https://www.apache.org/licenses/LICENSE-2.0");
return apiInfo;
}
Now build and start your application and hit below end point in browser
http://localhost:8090/swagger-ui.html