springspring-bootjerseyspringdocspring-jersey

How to make springdoc openapi available in spring boot app while using jersey?


I am using spring boot 3.3.2 with jersey (using jakarta.ws annotations). Dependencies:

<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>

After registering OpenApiResource I get this error at runtime:

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
    }
}

thus making openapi unavailable.

Main class:

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

Am I missing some configuration or dependencies?


Solution

  • At the time of writing this answer, jersey is not supported.

    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