如何在使用 jersey 时使 springdoc openapi 在 Spring Boot 应用程序中可用?

问题描述 投票:0回答:1

我正在使用 Spring Boot 3.3.2 和 jersey (使用 jakarta.ws 注释)。依赖关系:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.6.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.test-framework.providers</groupId>
    <artifactId>jersey-test-framework-provider-jetty</artifactId>
    <version>3.1.8</version>
    <scope>test</scope>
</dependency>

注册 OpenApiResource 后,我在运行时收到此错误:

A provider org.springdoc.webmvc.api.OpenApiResource registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider org.springdoc.webmvc.api.OpenApiResource will be ignored.

@Configuration
public class WsResourceConfig extends ResourceConfig {
    public WsResourceConfig() {
        packages("resource.packages");
        register(MultiPartFeature.class);
        register(OpenApiResource.class); // registration
    }
}

从而导致 openapi 不可用。

主要课程:

@SpringBootApplication
public class Main extends SpringBootServletInitializer {

    // dev only
    public static void main(final String[] args) {
        new SpringApplicationBuilder(Main.class)
                .listeners(new DatabasePropertiesSetup())
                .run(args);
    }

    // when deployed to servlet container
    @Override
    protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.listeners(new DatabasePropertiesSetup())
                .sources(Main.class);
    }
}

我是否缺少一些配置或依赖项?

spring spring-boot jersey springdoc spring-jersey
1个回答
0
投票

在撰写此答案时,球衣不支持

13.19. Does springdoc-openapi support Jersey?

If you are using JAX-RS and as implementation Jersey (@Path for example), we do not support it.

We only support exposing Rest Endpoints using Spring managed beans (@RestController for example).

You can have a look at swagger-jaxrs2 project:

    https://github.com/swagger-api/swagger-samples/tree/2.0/java/java-jersey2-minimal
© www.soinside.com 2019 - 2024. All rights reserved.