Search code examples
spring-bootjava-8swagger-uispringdoc-openapi-ui

Springdoc openapi and Spring boot parent 2.7.10 compatibility


I upgraded my applications spring-boot-starter-parent version to 2.7.10.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.10</version>
</parent>

<properties>
   <java.version>1.8</java.version>
<properties>

Along with this I integrated my app to OpenApi for which I added dependency like this

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.8</version>
    <type>pom</type>
</dependency>

After this I'm able to access my swagger here http://localhost:8080/v3/api-docs but I can see it as JSON response. To get the typical swagger ui page I was recommended to add below dependency while removing the springdoc-openapi-ui

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.0</version>
</dependency>

I even tried using below dependency yet I get the same error

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
        <version>2.0.0</version>
    </dependency>

Below is my Swagger configuration class

@Bean
public OpenAPI customOpenAPIConfig() {
    return new OpenAPI().info(buildInfo());
}

private Info buildInfo() {
    return new Info()
            .title("WTS-Config Shipper Preferences API")
            .description("Shipper Preference API to create rules");
}

Now when I run the app in local I'm getting below error

Caused by: java.lang.UnsupportedClassVersionError: org/springdoc/core/conditions/MultipleOpenApiSupportCondition has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

My project is currently using Java 1.8 and I'm running this app in IntelliJ IDEA and I made sure all the settings are set to Java8 including the compiler etc. In fact I do not have any other java versions installed in my mac.

My goal is to access the application with Swagger UI: http://localhost:8080/swagger-ui.html


Solution

  • The springdoc-openapi-starter-webmvc-ui and springdoc-openapi-starter-webmvc-api dependencies only support JDK 17 and Spring Boot 3.x. If you want to use Spring Boot 2.x, please use springdoc-openapi-ui dependency.