Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

메모장

Swagger 본문

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

'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