gpt4 book ai didi

spring-boot - spring boot 不支持同组名的多个 Docket

转载 作者:行者123 更新时间:2023-12-05 00:47:57 26 4
gpt4 key购买 nike

我有以下用于 swagger 的 Spring Boot 配置,当服务启动时出现以下错误,我不确定为什么会这样。我遵循了一个教程,它适用于他们。

java.lang.IllegalStateException: Multiple Dockets with the same group name are not supported. The following duplicate groups were discovered. default


@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SpringFoxConfig {

@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("test.rest"))
.paths(PathSelectors.ant("/test/**"))
.build()
.apiInfo(apiInfo());
}

// Describe the apis
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("test")
.description("Test")
.version("1.0.0")
.license("vvv")
.build();
}

}

我还有另一个配置

@OurApp
@EnableSwagger2
public class CoreApp extends OurApp {

}

最佳答案

在这里,您尝试使用相同的组名执行多个 Docket,这是 Not Acceptable 。请查看提供的链接。

groupName(java.lang.String groupName) If more than one instance of Docket exists, each one must have a unique groupName as supplied by this method. Documentation

public class Docket implements DocumentationPlugin {
public static final String DEFAULT_GROUP_NAME = "default";
}

您可以在上面看到 DocumentPlugin 的 groupname 为“default”。

public Docket(DocumentationType documentationType) {
this.apiInfo = ApiInfo.DEFAULT;
this.groupName = "default";

上面有“默认”作为组名。

因此,您需要为两个 Docket 设置两个不同的组名。

你需要做的就是改变你的代码如下:覆盖现有的默认组名。

@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SpringFoxConfig {
@Bean
public Docket apiDocket() {
String groupName = "Swagger";
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("test.rest"))
.paths(PathSelectors.ant("/test/**"))
.build()
.groupName(groupName)
.apiInfo(apiInfo());
}

// Describe the apis
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("test")
.description("Test")
.version("1.0.0")
.license("vvv")
.build();
}
}

关于spring-boot - spring boot 不支持同组名的多个 Docket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54903534/

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