메모장
Swagger 본문
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
'Java' 카테고리의 다른 글
스프링 컨테이너(IoC) (0) | 2023.01.19 |
---|---|
Gmail SMTP 메일 발송 (0) | 2023.01.18 |
게시판 파일 수정 (0) | 2023.01.11 |
@AuthenticationPrincipal 이용한 게시판 접근 제한 (0) | 2023.01.10 |
CustomUserDetails, CustomUserDetailsService (0) | 2023.01.10 |