访问swagger-ui页面错误重现+解决策略

说在前面:swagger版本用的是2.9.2 使用的springfox 可以直接根据代码来生成接口文档

在pom文件中引入依赖:

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

然后写一个测试控制器来测试一下:

@RestController

@RequestMapping("/people")
public class DemoController {
    @GetMapping("/hello")
    public String test(Long id,String name){
        return name;
    }
}

在启动类中加入注解EnableSwagger2:

@SpringBootApplication
@EnableSwagger2
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

这样就行了吗?
当然没有

会报以下错误:

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

解决的办法就是在yml文件中添加

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

输入网址访问即可:访问swagger-ui的地址
这里只测试了2.9.2版本 ,在测试3.0版本时会报找不到页面错误。有知道的小伙伴可以在评论区留言啊

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

烈焰星辰

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

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

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

打赏作者

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

抵扣说明:

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

余额充值