Spring & SpringBoot

[Error] SpringBoot -Swagger 연결 에러(org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException)

Hyeonni 2022. 4. 4. 16:19

API를 개발하고 나면 해야하는 일은 바로 API 명세서 작성이다. 

API 명세서를 작성하는데 있어서 미루고 미루다보면 나중에 산더미처럼 쌓이기 마련이다,,

그래서 swagger를 이용해서 자동 API 명세서 작성을 도전해보려고 했는데!

아래와 같은 문제가 발생했다.

 

 

Error 내용

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

 

아래는 에러 내역의 일부이다.

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.18.jar:5.3.18]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.18.jar:5.3.18]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
	at com.gahyeonn.swagger.SwaggerApplication.main(SwaggerApplication.java:10) ~[main/:na]

 

먼저 개발 환경은 아래와 같다.

 

  • springboot : 2.6.6
  • swagger : 3.0.0

 

Error 원인

 

Spring boot 2.6 버전 이후에 위와 같은 에러가 발생한다고 한다.

 

발생 원인은 spring.mvc.pathmatch.matching-strategy 값이 ant_apth_matcher에서 path_pattern_parser로 변경되면서 swagger 포함 라이브러리에 오류가 발생한다고 한다.

 

 

해결 방법

 

해결 방법은 application.yml 파일에 아래 코드를 추가해 주면 된다.

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

 

그렇다면 이제 편하게 swagger로 api 명세서를 생성해봐야겠다~!

(코드가 살짝 더러워지는 느낌이 있지만,,,ㅎ)