[에러] [SpringBoot] Swagger 'No operations defined in spec!' 에러 해결

손경이·2024년 5월 14일
0

에러모음

목록 보기
19/20

2024.05.14
[책 - 스프링 부트 핵심 가이드]
환경 - 스프링부트 2.5.6, 자바 JDK11, Gradle 프로젝트
스프링 부트 핵심 가이드 valid_exception 연습 - 'Swagger 관련된 설정 코드' 깃허브

❗ 에러 문구

  • No operations defined in spec!

📸 에러 캡쳐

  • Swagger 적용 후 Swagger 페이지에서 API가 보이지 않는다.

🔎 에러 이유 및 해결

  • 에러 이유

    • apis(RequestHandlerSelectors.basePackage("com.springboot.valid_exception")) 에서 valid_exception은 적지 않고 SwaggerConfig를 복사해오는 과정에서 이전에 사용한 폴더를 적어서 Swagger가 스캔하는데 에러가 생긴 것이었다.
  • 해결 방법

    • apis에서 Swagger에서 스캔할 패키지 범위의 폴더를 바꿔주었다.
/**
 * Swagger 관련된 설정 코드
 * http://localhost:8080/swagger-ui.html 확인
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.springboot.valid_exception")) // Swagger에서 스캔할 패키지 범위
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot Open API Test with Swagger")
                .description("설명 부분")
                .version("1.0.0")
                .build();
    }
}
  • 해결 완료


참고

0개의 댓글