Java
Swagger
doopang
2023. 1. 13. 14:47
build.gradle
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'io.swagger:swagger-annotations:1.6.6'
implementation 'io.swagger:swagger-models:1.6.6'
SwaggerConfig
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.aaa.bbb.ccc.controller"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false);
}
private ApiInfo getApiInfo() {
return new ApiInfoBuilder()
.title("title")
.description("description")
.license("license")
.version("v1")
.build();
}
}
Controller
@Api("공지사항")
@RestController
@RequiredArgsConstructor
@RequestMapping("/notice")
public class NoticeController {
private final ResponseService responseService;
private final NoticeService noticeService;
@GetMapping("/{noticeSeq}")
@ApiOperation("공지사항 조회")
public CommonResult getNotice(@PathVariable Long noticeSeq) {
return responseService.getSingleResult(noticeService.getNotice(noticeSeq));
}
}
URL: http://localhost:8080/swagger-ui.html