gpt4 book ai didi

spring - 如何在 spring-mvc 中为 springfox(更准确的 springfox-swagger2)设置主机 url?

转载 作者:行者123 更新时间:2023-12-05 02:20:30 24 4
gpt4 key购买 nike

我有 spring-mvc 应用程序,我已经嵌入了 RestAPI。一切正常,我的 rest api 映射到 /rest/* url。当我添加 SwaggerConfig 它已经开始识别我的 Controller ,但是当我在 swagger-ui 中尝试它时(gui 形式以简化消费者与 api 的交互) enter image description here

我有 404 未找到状态。因为这试过了 enter image description here这不会对有效的 url 进行请求

http://localhost:8080/ProductCatalog/rest/branch?id=1

虽然 SwaggerConfig 映射到正确的 url,因为我在编写时得到了这个 GUI 表示

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

根 url 上有一个应用程序的主要部分(这不是我工作的部分)我的部分映射到 /rest/*我怎样才能改变 /rest/* 上的这个“试试看”网址呢?我的 SwaggerConfig

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket pscApi() {
return new Docket(DocumentationType.SWAGGER_2)
//.groupName("PSC");
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("restService.com.websystique.springmvc"))
.paths(PathSelectors.any())
.build();
//PathSelectors.regex("/api/.*")
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("RestApiOfPSC")
.description("REST API for PSC.")
.build();
}
}

我也指定了这个

@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/");
}

抱歉我的英语不好,在此先感谢

最佳答案

我知道如何做到这一点。

docket.pathMapping("/rest");

有时你需要换一种方式在你的 Docket bean 中写入 docket.host("your host url");更准确地阅读我的问题 https://github.com/springfox/springfox/issues/1468

并阅读引用#issue1050。

关于spring - 如何在 spring-mvc 中为 springfox(更准确的 springfox-swagger2)设置主机 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39147582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com