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

无法更改swagger UI路径

徐德海
2023-03-14

我正在使用Swagger为Spring boot2微服务创建API留档,我是Swagger的新手。我的Spring启动应用程序具有上下文路径 /api/user/因此该应用程序可在localhost:8080/api/user访问。swagger默认用户界面可在/swagger-ui.html访问。所以从我的项目来看,网址是localhost:8080/api/user/swagger-ui.html/但我出错了

Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "swagger-ui.html"

因为有apilocalhost:8080/api/user/{id}。我无法更改微服务的联系路径。请建议如何将自定义路径添加到swagger用户界面,以便swagger用户界面可以在urllocalhost:8080/api/user/swagger/swagger-ui.html或localhosr: 8080/swagger/swagger-ui.html.以下是我的配置文件

@Configuration
public class SwaggerConfiguration{

    //...

    
      @Bean
      public Docket api(ServletContext servletContext) {
        return new Docket(DocumentationType.SWAGGER_2)
            .securitySchemes(Arrays.asList(apiKey()))
            .securityContexts(Collections.singletonList(securityContext()));
      }

      private SecurityContext securityContext() {
        return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex("/.*")).build();
      }

      private List<SecurityReference> defaultAuth() {
        final AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
        final AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
        return Collections.singletonList(new SecurityReference("Bearer", authorizationScopes));
      }

      private ApiKey apiKey() {
        return new ApiKey("Bearer", "Authorization", "header");
      }
      
} 

共有1个答案

叶阳
2023-03-14

您点击了错误的URL。

Swagger UI位于:

 http://localhost:8080/swagger-ui.html

如果需要配置路径,可以在应用程序中更改路径。yml(示例):

springdoc:
  swagger-ui:
    path: /documentation/swagger-ui-my-project.html

如果需要更多信息,请提供带招摇过市设置的教程:https://dzone.com/articles/spring-boot-swagger-3-openapi-3-security-exampleba

 类似资料:
  • 我正在使用RHEL8,它安装了默认的OpenJDK。哪个java命令指向/usr/bin/java。java-version提供openjdk版本“1.8.0_252” 已在/u01/app/java/location中安装java。修改了。如下图所示 现在JAVA_HOME指向/u01/app/JAVA/jdk1。8.0_241/但哪种java或java版本仍然指向OpenJDK。 bash_p

  • SwaggerUI 汉化版;修改了部分样式;结合SpringFox SpringFox-Swagger-UI实现API管理

  • 本文向大家介绍ubuntu mysql更改tmp路径的方法,包括了ubuntu mysql更改tmp路径的方法的使用技巧和注意事项,需要的朋友参考一下 ubuntu系统是一个linux操作系统;下面呐喊教程小编给大家介绍ubuntu mysql更改tmp路径的方法。 因为mysql经常要把文件定入tmp目录,而tmp的目录为/tmp,为了提高性能,所以考虑更改tmpdir目录为/run/shm,即

  • 我创建了一个表格,插入拳头的名字,姓氏和电话,但我有这个错误,不能弄清楚它在哪里 这是我的php代码第一个名为displayPhone的文件。php 第二个文件名为savePhone。php 我的库名'宠物'表名'数据'。该表包含3部分first_name,last_name和电话都是varchar类型

  • 您好,我正在使用Laravel5.2版本。我通过composer安装了laravel项目。之后,我使用命令“phpartisanmake:auth”创建auth。创建身份验证路由后生成,例如“http://localhost:8000/login“.现在我不想要此路线,我想设置不同的路线,例如”http://localhost:8000/super/admin“那么,我该如何更改”http://l