Failed to start bean ‘documentationPluginsBootstrapper‘ NullPointerException

最近把项目升级了springboot2.6.1版本,发现启动报错,

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.6.jar:5.3.6]
at org.springframework.context.support.DefaultLifecycleProcessor.access 200 ( D e f a u l t L i f e c y c l e P r o c e s s o r . j a v a : 54 )   [ s p r i n g − c o n t e x t − 5.3.6. j a r : 5.3.6 ] a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . D e f a u l t L i f e c y c l e P r o c e s s o r 200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.6.jar:5.3.6] at org.springframework.context.support.DefaultLifecycleProcessor 200(DefaultLifecycleProcessor.java:54) [springcontext5.3.6.jar:5.3.6]atorg.springframework.context.support.DefaultLifecycleProcessorLifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.6.jar:5.3.6]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_77]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:772) [spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:441) [spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) [spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) [spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1339) [spring-boot-2.5.0-20210413.204210-414.jar:2.5.0-SNAPSHOT]
at com.example.demo.DemoApplication.main(DemoApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null

经过各种尝试发现是springfox还没有适配最新版,解决办法要么降低spring版本,要么根据官方迁移文档使用最新的springdoc。我才用了后者。使用方法很简单删除 springfox 和 swagger 2 依赖项。添加springdoc-openapi-ui依赖项。

implementation(“org.springdoc:springdoc-openapi-ui:1.5.12”)

application.properties添加扫描

springdoc.packagesToScan=package1, package2

注册Bean

@Configuration
class SwaggerConfiguration {

    @Bean
    fun springShopOpenAPI(): OpenAPI? {
        return OpenAPI()
            .info(
                Info().title("Spring API")
                    .description("Spring shop sample application")
                    .version("v1.0")
                    .license(License().name("Apache 2.0").url("https://springdoc.org"))
            )
            .externalDocs(
                ExternalDocumentation()
                    .description("SpringShop Wiki Documentation")
                    .url("https://springshop.wiki.github.org/docs")
            )
    }
}

在这里插入图片描述

更多使用方法可以查看官方文档https://springdoc.org/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Marblog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值