use swagger with spring boot code example
Example 1: spring boot example with swagger
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
Example 2: swagger implementation in spring boot
package com.bhutanio.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket bookHotelApi() {
return new Docket( DocumentationType.SWAGGER_2)
.select()
.apis( RequestHandlerSelectors.any())
.paths( PathSelectors.any())
.build()
.apiInfo(getApiInfo());
}
private ApiInfo getApiInfo() {
return new ApiInfoBuilder()
.title("Swagger By Bhutan IO")
.version("1.0")
.description("Some description here..")
.contact(new Contact("Bhutan IO", "http://www.bhutanio.com", "[email protected]"))
.license("Apache License Version 2.0")
.build();
}
}Code language: JavaScript (javascript)