728x90
Dependency
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
SwaggerConfig
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swaggerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(swaggerInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.nextloop.nearlog"))
.paths(PathSelectors.ant("/api/v1/**"))
.build();
}
private ApiInfo swaggerInfo() {
return new ApiInfoBuilder()
.title("Spring API Documentation")
.description("nearlog 서버 API 문서")
.license("bgpark")
.licenseUrl("https://bgpark.tistory.com/")
.contact("bgpark82@gmail.com")
.build();
}
}
사용하기
@Api(tags = "Hello")
@RestController
@RequestMapping(("/api/v1"))
public class HelloController {
@ApiOperation(value = "에러 메세지", notes = "에러 메세지를 생성한다")
@GetMapping
public String hello() {
throw new ApiException(ErrorCode.SERVER_ERROR);
}
}
접속
http://localhost:8080/swagger-ui.html
728x90