java - Swagger UI 不适用于 JSON 配置
问题描述
我已经删除了 @EnableSwagger2 & io.springfox:springfox-swagger2 依赖项,以便不使用传统的 swagger 相关注释,而是使用 JSON 文件。
我已使用此处共享的详细信息将 Swagger 从基于注释的注释更改为基于 JSON:Overcoming Swagger Annotation Overload by Switching to JSON
有人可以帮我解决可能导致问题的原因吗?
解决方案
我认为您没有在 Pom.xml 文件中添加 swagger 依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>
我认为这可能是它没有打开 Swagger UI 的原因。请尝试在配置文件中创建bean,以便swagger可以正常运行。
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.cloud")))
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.data.rest.webmvc")))
.paths(PathSelectors.any()).build();
}}
推荐阅读
- python - 如何打印路由到装饰器@route的烧瓶功能
- flutter - 颤动如何捕捉错误谷歌登录
- javascript - Vue3.0中按键绑定按钮
- java - 是否可以在 Mono/Flux 中创建动态过滤器/谓词?
- database - 如何仅将新值发布到表中。PostgreSQL
- node.js - Heroku 使用旧的依赖项?
- python - 如何在 django 模板中使用过滤器执行查询
- python - 使用值评估表达式
- flutter - 如何制作具有 2 个提示文本的 TextField?
- python - 在带有 Tensorflow 的 Keras 中,如何重新索引 nd 张量的轴?