Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Upgrade to openAPI not compiling

We are doing a major upgrade from jave 8 to java 21 so we are having to upgrade many things all at once.

I am getting this crazy compiler error, I am running mvn compile and getting this error message.

[ERROR] /C:/dev/workspaces/.../src/main/java/com/.../config/SwaggerConfig.java:[13,49] cannot find symbol
[ERROR]   symbol:   class builder
[ERROR]   location: class org.springdoc.core.models.GroupedOpenApi
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public GroupedOpenApi  api() {
        GroupedOpenApi api =  new GroupedOpenApi.builder()
          .pathsToMatch("/path/**")   
                .build()
          ;                                           
    }

}

I have these dependencies in my pom.xml

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.6.0</version>
        </dependency>

>Solution :

if you look inside of GroupedOpenApi you will see that builder() is a static method:

public static Builder builder() {
    return new Builder();
}

as well as the constructor is private:

private GroupedOpenApi(Builder builder) {
   ...
}

Therefore simply remove the keyword new for it to work:

@Bean
public GroupedOpenApi api() {
    return GroupedOpenApi.builder()
                .pathsToMatch("/path/**")
                .build();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading