我的应用程序未启动Sping MVC。
我正在使用springdoc-openapi-ui 1.4.4
另外,我将以下导入添加到我的@configuration类之一;
org.springdoc.core.SpringDocConfigProperties.class, org.springdoc.core.SpringDocConfiguration.class,
org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
org.springdoc.webmvc.core.MultipleOpenApiSupportConfiguration.class,
org.springdoc.core.SwaggerUiConfigProperties.class, org.springdoc.core.SwaggerUiOAuthProperties.class,
org.springdoc.webmvc.ui.SwaggerConfig.class, org.springdoc.core.CacheOrGroupedOpenApiCondition.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class })
并按如下所示实现bean
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("user")
.pathsToExclude("/api/v2/**", "/v2/**")
.pathsToMatch("/api/v1/**", "/v1/**")
.build();
}
@Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder()
.group("admin")
.pathsToExclude("/api/v1/**", "/v1/**")
.pathsToMatch("/api/v2/**", "/v2/**")
.build();
}
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components())
.info(new Info()
.title("titleI")
.version("1.0.0"));
}
但是当我尝试http://localhost:8080/MyApp/v3/api-docs/user
给我404。
但是我得到了http://localhost:8080/MyApp/v3/api-docs
它也出现在http://www.onlykalu.com:81/MyApp/swagger-ui/index.html?configUrl=/MyApp/v3/api-docs/swagger-config
也没有定义下拉列表。
如果我添加
springdoc.group-configs[0].group=user
springdoc.group-configs[1].group=admin
进入application.properties然后我得到
我做错了什么?
我是否需要导入其他任何类才能使组功能正常工作?
谢谢
答案 0 :(得分:2)
您的问题也在这里提出:
如前所述,您只需要将Beans定义放在专用的配置类中,然后将其添加到springdoc-openapi Beans导入中,即可通过相同的机制加载Beans。
这是正确的bean配置:
@Configuration
public class GroupsConfiguration {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder().group("user").pathsToExclude("/api/v2/**").pathsToMatch("/api/v1/**").build();
}
@Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder().group("admin").pathsToExclude("/api/v1/**").pathsToMatch("/api/v2/**").build();
}
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().components(new Components()).info(new Info().title("Spring MVC REST API")
.contact(new Contact().name("Rasika Kaluwalgoda")).version("1.0.0"));
}
}
springdoc-openapi与GroupsConfiguration一起一起导入:
@Configuration
@Import({ org.springdoc.core.SpringDocConfigProperties.class,
org.springdoc.webmvc.core.MultipleOpenApiSupportConfiguration.class,
org.springdoc.core.SpringDocConfiguration.class, org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
SwaggerUiConfigParameters.class, SwaggerUiOAuthProperties.class,
org.springdoc.core.SwaggerUiConfigProperties.class, org.springdoc.core.SwaggerUiOAuthProperties.class,
org.springdoc.webmvc.ui.SwaggerConfig.class, GroupsConfiguration.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class })
public class SwaggerConfig {
}