环境:Swagger3.0 和SpringBoot.6.5
可能出现的问题:
| 1.SpringBoot 无法启动 Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException |
原因是:因为Springfox 使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher。对应解决办法有两种配置文件或者配置类。
解决问题1
Swagger2相关-拓展思路
Swagger一些注解说明
| 2.Swagger3.0swagger-ui/index.html无法访问 404 首先注意这里使用的版本是Swagger3.0 访问路径不是swagger-ui.html其次注意加入注解@EnableOpenApi以及更新对应的依赖 |
解决问题2
解决问题2
我的项目:
org.springframework.boot
spring-boot-starter-parent
2.6.5
1.8
2.6.5
8.0.23
1.2.6
2.2.0
1.18.24
3.0.0
1.2.83
2.13.3
io.springfox
springfox-boot-starter
${swagger.version}
| 2.application.yaml--端口号8780(你也可以默认8080) |
Server:
port: 8780
Spring:
datasource:
druid:
url: jdbc:mysql://127.0.0.1:3306/mybatis_demo?serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 1234
mvc:
pathmatch:
matching-strategy: ant_path_matcher
application:
name: mybatis-demo
mybatis:
mapper-locations: classpath:mapper
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("网站-API文档") // 可以用来自定义API的主标题
.description("本文档描述了网站微服务接口定义") // 可以用来描述整体的API
.termsOfServiceUrl("") // 用于定义服务的域名
.version("1.0") // 可以用来定义版本。
.contact(new Contact("practice-lij", "http://www.baidu.com", "atguigu.com"))
.build();
}
}
| 6.访问网址:http://localhost:8780/swagger-ui/index.html |
暑期编程PK赛
得CSDN机械键盘等精美礼品!