spring에 swagger 적용하면서 겪은 3가지 에러 해결하기

2023. 9. 22. 12:12·Backend/Spring Boot

스프링 2.X.X 특정 버전 이후로 Swagger2:2.X.X 버전 실행 에러 발생

해결 -> build.gradle파일의 springfox ~ 버전들을 모두 3.0.0 으로 바꿔준다.

// Swagger Lib
	implementation 'io.springfox:springfox-swagger2:3.0.0'
	implementation 'io.springfox:springfox-swagger-ui:3.0.0'
	implementation 'io.springfox:springfox-boot-starter:3.0.0'

 

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 에러 발생

해결책 -> application.yml 에서 아래 내용 추가해주기

  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

 

 

 

[SwaggerConfig.java] 

package com.board.fullstack;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2)
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.board.fullstack"))
				.paths(PathSelectors.any())
				.build();
	}
}

 

 

 

http://localhost:8080/swagger-ui.html 로 접속 시 Whitelabel Error Page 에러 발생

http://localhost:8080/swagger-ui.html는 Swagger 2.X.X에서 접속가능한 주소라고 한다. Swagger 3이상을 사용한다면 http://localhost:8080/swagger-ui/index.html 로 접속하도록 하자 !

 

정상적으로 접속된 모습 !!!!!!

'Backend/Spring Boot' 카테고리의 다른 글
  • Query did not return a unique result: 2 results were returned 에러 해결하기
  • Content type 'application/octet-stream' not supported 에러
  • prepareKotlinBuildScriptModel Task fails in a Java project 오류 해결
  • assertThat 라이브러리 추가하기
kimdozzi
kimdozzi
끝까지 포기하지 않으면, 내가 다 이겨!
  • kimdozzi
    도브로
    kimdozzi
  • 전체
    오늘
    어제
    • 분류 전체보기 (132)
      • Problem Solving (49)
        • Baekjoon (29)
        • Programmers (0)
        • LeetCode (17)
        • 삼성 유형 (2)
      • Computer Science (27)
        • Operating System (2)
        • Algorithms (13)
        • Network (6)
        • DataBase (6)
      • Backend (33)
        • JavaScript (0)
        • TypeScript (6)
        • Java (7)
        • Spring Boot (7)
        • Spring Security (6)
        • JPA (2)
        • Mybatis (1)
        • Junit5 (1)
        • Redis (3)
      • DevOps (14)
        • Git, Github (5)
        • docker (4)
        • AWS (3)
        • nginx (2)
      • etc (6)
        • IntelliJ (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 티스토리
    • 설정
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    오프라인 쿼리
    누적합
    AWS
    구간합
    파이썬
    Bucket
    인덱서블 타입
    점 업데이트
    삼성기출
    컨테이너
    S3
    CORS
    docker image
    구간 업데이트
    알고리즘
    imos법
    segment tree
    세그먼트 트리
    백준
    인터페이스
    티스토리챌린지
    PrefixSum
    오블완
    타입스크립트
    python
    도커
    인덱스 시그니처
    docker
    TypeScript
    온라인 쿼리
    interface
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
kimdozzi
spring에 swagger 적용하면서 겪은 3가지 에러 해결하기
상단으로

티스토리툴바