使用swagger报错:Exception encountered during context initialization - cancelling refresh attempt解决方法

今天在使用swagger时遇到了如下报错:

WARN 19704 --- [           main] 
ConfigServletWebServerApplicationContext :
 Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper';
 nested exception is java.lang.NullPointerException

查了资料发现是swagger版本与springboot版本不兼容的问题,在spring配置文件 application.properties 中添加如下代码成功解决:

spring.mvc.pathmatch.matching-strategy=ant_path_matcher
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.4)

2022-10-10 19:24:46.945  INFO 16516 --- [           main] com.atguigu.eduservice.EduApplication    : Starting EduApplication using Java 1.8.0_322 on LAPTOP-7FA7QIA3 with PID 16516 (D:\IDEA_files\guli_parent\service\service_edu\target\classes started by 16937 in D:\IDEA_files\guli_parent)
2022-10-10 19:24:46.947  INFO 16516 --- [           main] com.atguigu.eduservice.EduApplication    : The following 1 profile is active: "dev"
2022-10-10 19:24:47.498  INFO 16516 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-10-10 19:24:47.500  INFO 16516 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2022-10-10 19:24:47.514  INFO 16516 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6 ms. Found 0 Redis repository interfaces.
2022-10-10 19:24:47.844  INFO 16516 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8001 (http)
2022-10-10 19:24:47.850  INFO 16516 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-10-10 19:24:47.850  INFO 16516 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-10 19:24:48.000  INFO 16516 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-10-10 19:24:48.000  INFO 16516 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1026 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.0.5 
2022-10-10 19:24:48.141  INFO 16516 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-10-10 19:24:48.370  INFO 16516 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
Property 'mapperLocations' was not specified or no matching resources found
2022-10-10 19:24:48.678  INFO 16516 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2022-10-10 19:24:49.085  INFO 16516 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8001 (http) with context path ''
2022-10-10 19:24:49.086  INFO 16516 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2022-10-10 19:24:49.097  INFO 16516 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2022-10-10 19:24:49.119  INFO 16516 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2022-10-10 19:24:49.216  INFO 16516 --- [           main] com.atguigu.eduservice.EduApplication    : Started EduApplication in 2.539 seconds (JVM running for 3.588)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值