๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
BackEnd๐ŸŒฑ/Spring

[Spring] nested exception is java.lang.NullPointerException

by dkswnkk 2022. 5. 15.

์„œ๋ก 

spring boot 2.6.7์„ ์‚ฌ์šฉ ์ค‘์ด๊ณ  swagger 3.0.0 ๋ฒ„์ „์„ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ง„ํ–‰ํ•˜๋˜ ์ค‘ ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

ํ˜„์žฌ gradle์„ ์‚ฌ์šฉ์ค‘์ด๊ธฐ์— ์•„๋ž˜์™€ ๊ฐ™์ด dependencies์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

implementation 'io.springfox:springfox-boot-starter:3.0.0'

maven์ผ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-swagger2</artifactId>
	<version>3.0.0</version>
</dependency>
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>3.0.0</version>
</dependency>
<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-boot-starter</artifactId>
	<version>3.0.0</version>
</dependency>

SwaggerConfig.java์˜ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage(""))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger Test")
                .description("SwaggerConfig")
                .version("3.0")
                .build();
    }
}

์›์ธ

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

์ •์ƒ ์ž‘๋™ํ•˜๋Š” ๋ชจ์Šต

 

์ฐธ๊ณ 

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#pathpattern-based-path-matching-strategy-for-spring-mvc

๋Œ“๊ธ€