当前位置: 首页 > 知识库问答 >
问题:

大摇大摆的用户界面没有出现

戚翼
2023-03-14

我当时正在从事spring项目。首先,我将swagger添加到我的项目中,我的swagger用户界面也显示了所有控制器,但当我将JWT承载令牌添加到我的项目中时。不知何故,我无法进入大摇大摆的用户界面。它会一直在我的浏览器中显示以下窗口。我怎样才能解决这个问题有什么想法吗?

在pom中。xml

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



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

配置类昂首阔步其他配置类我没有到目前为止

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SpringFoxConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("uzb.ofb.reportgen.controller"))
                .paths(PathSelectors.any())
                .build();
    }
}

使现代化

遵循代码后

@Configuration
@EnableSwagger2
public class SpringFoxConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui.html/")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("uzb.ofb.reportgen.controller"))
                .paths(PathSelectors.any())
                .build();
    }
}

共有3个答案

厍建义
2023-03-14

Swagger UI由webjar提供,您需要配置SpringMVC

    @Configuration
    @EnableSwagger2
    public class WebConfig implements WebMvcConfigurer {

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");

            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
    }
蔚和风
2023-03-14

您在项目中使用Spring Security性吗?尝试覆盖安全配置中的configure()methdod:

@Override
public void configure(WebSecurity web) {
    web.ignoring()
       .antMatchers("/webjars/**", "/swagger-resources/**", "/swagger-ui.html",
               "/v2/api-docs/**");
}
孟均
2023-03-14

您应该扩展WebMvcConfigrerAdapter并覆盖方法:

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");

            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
 类似资料:
  • 我成功地在Spring boot应用程序上应用了swagger ui,并能够使用http://localhost:8181/swagger-用户界面。html 过了一段时间,我继续写我的申请,现在它不见了。我没有拿走任何罐子。我添加了一个应用程序启动类,当我在Wildfly 10上部署时,该类用于在启动时加载一些东西。 即使我尝试用tomcat将其作为Spring boot应用程序运行,也无法运行

  • 理想情况下,我们将有一个显示所有标记为public的控制器/方法的大摇大摆的页面,以及另一个显示所有endpoint的密码安全endpoint。这可能吗?

  • 我有一个java项目(tomcat webapp)和一些REST Api。我想为他们生成大摇大摆的文档。我从本教程(github)开始。我没有maven我们使用蚂蚁任务。我加入了swagger-annotations-1.5.0。jar和所有随swagger jaxrs jar 1.5.0版本附带的jar(如果有用的话,我可以包括一个完整的列表),我已经注释了一些方法,我有一个如下的配置类: }

  • 有没有人用spring-data-rest配置了swagger。我知道swagger有DocumentationConfig类,它扫描所有spring-mvc请求映射。但是,如何将其用于spring-data-rest,因为没有定义显式的请求映射。非常感谢在这方面的任何帮助。此外,我还想知道,是否有其他支持Spring-Data-REST的文档框架。

  • 我想从spring boot 2中切换到Micronaut框架。而我也在为那些大摇大摆的场景而挣扎。 在spring boot 2项目中,我有以下依赖项: 和swaggreconfig.class: 它可以很好地启动swagger-ui和spring boot 2应用程序。 我应该向maven添加哪些依赖项,我应该创建哪些类来为Micronaut项目获得相同的结果?

  • 我们在我们的泽西应用程序中使用了@Role允许注释来限制用户对应用编程接口某些部分的访问。我们如何在SwaggerUI中显示这些信息? 到目前为止,我已经用@ApiOperation注释了方法以显示in/out参数,并尝试使用@Authorization/@AuthorizationScope,但我只为我们不使用的oauth2显示了它。最接近out case的是ApiKeyAuthDefiniti