2023. 8. 1. 09:00ㆍ오류 처리
Spring Boot에서 swagger를 사용하기 위해 아래와 같이 의존성을 추가하고, 서버를 실행하니 하니 오류가 발생했다.
//swagger
implementation 'io.springfox:springfox-boot-starter:3.0.0'
에러 로그
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
우선 위 에러를 대략 해석하자면 다음과 같다.
org.springframework.context.ApplicationContextException : 스프링 어플리케이션 컨텍스트에서 오류가 발생함
'documentationPluginsBootstrapper' bean : 'documentationPluginsBootstrapper'빈을 시작하는 도중에 문제가 발생
nested exception is java.lang.NullPointerException : 문제의 근본 원인은 NullpointerException 이다.
구글링을 통한 결론
Spring boot 2.6버전 이후에, spring.mvc.pathmatch.matching-strategy 값이 ant_apth_matcher 에서 path_pattern_parser로 변경되면서 오류가 발생할 수 있다.
문제 해결
mvc:
pathmatch:
matching-strategy: ant_path_matcher
swagger 사용 이유는?
@Operation(summary = "유저 생성 api", description = "유저 하나를 생성한다.")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "유저 생성 완료"),
@ApiResponse(responseCode = "401", description = "토큰 만료"),
@ApiResponse(responseCode = "403", description = "권한 없음"),
@ApiResponse(responseCode = "404", description = "해당 페이지 존재하지 않음"),
}
)
@PostMapping("/one")
public ResponseEntity<UserResponseDto> createOne(@RequestBody UserReqDto.CreateOne req) throws Exception {
return ResponseEntity.ok(userService.createOne(req));
}
위와 같이 컨트롤러에서 @Operation, @ApiResponses 어노테이션을 통해 응답을 제어할 수 있기 때문에 사용하게 되었다.
'오류 처리' 카테고리의 다른 글
[SQL 에러] You have an error in your SQL syntax; check the manual... (1) | 2023.07.31 |
---|