我的SpringBoot版本是2.7的,Swageer是2.9.0
这个错误在网上看了一大堆,都没有解决,后面自己搜了好久才找到解决方案,一般大家都是看到第三种的解决方式,然后出现了控制台报错,控制台报错在appliction中加配置
下面是几个可能出现的问题,下面给大家总结下
!!注意~~~~ 如果第三步加上之后发现控制台报了空指针的错误,不急,把第四步代码加上就可以解决了,我是这样解决的哈哈哈,希望你们也可以
四、application.properties加上一行代码
一、没有导入依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<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>
二,看看config配置里面有没有加上注解
@Configuration
@EnableSwagger2 //开启Swagger
public class SwaggerConfig {
}
三、在启动类加上注解
@ComponentScan(basePackages = {"com.tao.config"}) //“ ”内是自己的config文件路径
package com.tao.springbootswagger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@ComponentScan(basePackages = {"com.tao.config"})
public class SpringBootSwaggerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootSwaggerApplication.class, args);
}
}
!!注意~~~~ 如果第三步加上之后发现控制台报了空指针的错误,不急,把第四步代码加上就可以解决了,我是这样解决的哈哈哈,希望你们也可以
四、application.properties加上一行代码
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
然后再启动试一下,注意要把浏览器缓存清除下!!!!!!
完结撒花,这些内容是我自定义的哈哈哈, 如果解决了问题记得点赞,谢谢啦 🤭