【问题标题】:Swagger UI not working with JSON configurationSwagger UI 不适用于 JSON 配置
【发布时间】:2018-04-30 06:35:09
【问题描述】:

我已经移除了 @EnableSwagger2 & io.springfox:springfox-swagger2 依赖,以便不使用传统的 swagger 相关注解,而是使用 JSON 文件。

我已使用此处共享的详细信息将 Swagger 从基于注释的注释更改为基于 JSON:Overcoming Swagger Annotation Overload by Switching to JSON

但现在显示的是

有人可以帮我解决可能导致问题的原因吗?

【问题讨论】:

  • @helen 不,实际上所有这些问题都在使用 '@EnableSwagger2' 和相关注释,但我想使用 JSON 而不是那些。参考:dzone.com/articles/…

标签: java spring swagger swagger-ui


【解决方案1】:

我认为你没有在 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();
    }}

【讨论】:

  • 我有那个依赖,它工作得很好,但是我试图在没有这个依赖和任何类型的招摇相关注释的情况下做同样的事情。参考:dzone.com/articles/…
猜你喜欢
  • 1970-01-01
  • 2019-08-03
  • 2019-04-24
  • 2016-07-31
  • 2018-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多