Spring Boot 3 Springdoc-Openapi-Ui Doesn't Work

Spring Boot 3 Springdoc-Openapi-Ui Doesn't Work

I'm trying to add swagger-ui (OpenAPI 3.0) to a Spring Boot v3 application.

I've added the openapi-ui maven dependency, and it should work as per the documentation.

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.11</version>
</dependency>

But apparently, it still doesn't work and localhost:8080/swagger-ui.html returns an 404 error.

What am I missing?

1

13 Answers

According to the documentation:

For spring-boot 3 support, make sure you use springdoc-openapi v2

What is the compatibility matrix of springdoc-openapi with spring-boot?

For the integration between spring-boot and swagger-ui, add the library to the list of your project dependencies (No additional configuration is needed)

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

This will automatically deploy swagger-ui to a spring-boot application:

Documentation will be available in HTML format, using the official swagger-ui jars

The Swagger UI page will then be available at and the OpenAPI description will be available at the following url for json format:

server: The server name or IP

port: The server port

context-path: The context path of the application

Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml

Please note that modules have been renamed:

5

I completely agreed with @JCompetence. Please note that springdoc-openapi-ui now changed to springdoc-openapi-starter-webmvc-ui from spring boot 3.

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

Please try this. If you want to find more info, please check the official link:

1

For me it helped, just changed the dependency

   implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'

to

    implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'

or

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

You need to use springdoc-openapi

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

for kotlin you must add one dependency more

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-kotlin</artifactId>
</dependency>

then add `@OpenAPIDefinition on your main class

@SpringBootApplication
@OpenAPIDefinition
class MyApplication {
}
3

springdoc-openapi-starter-webmvc-ui doesn't work with spring-boot-starter-webflux until you include spring-boot-starter-web. If you include spring security then it is dead.

2

Just an add-on if your application have spring security enabled !! Then you will need to whitelist swagger-endpoint to not use authentication

@Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().disable().authorizeHttpRequests(auth -> {
            auth.requestMatchers("/v3/**", "/swagger-ui/**").permitAll();
            auth.anyRequest().authenticated();
        });

return httpSecurity.build();

Maven plugin to generate (Java) code from OpenApi spec (.yml files)

Generator “spring” supports Jakarta namespace

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <configuration>
        <configOptions>
            ...
            **<useSpringBoot3>true</useSpringBoot3>**
        </configOptions>
    </configuration>
</plugin>

Generator “java” (to generate a client) doesn’t support Jakarta namespace yet. So use the Eclipse Transformer plugin (Javax dependencies need provided scope!)

 <plugin>
        <groupId>org.eclipse.transformer</groupId>
        <artifactId>transformer-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <rules>
           <jakartaDefaults>true</jakartaDefaults>
         </rules>
       </configuration>
        <executions>
            <execution>
                <id>jakarta-ee</id>
                <goals><goal>jar</goal></goals>
                <phase>package</phase>
                <configuration>
                    <artifact>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                    </artifact>
                </configuration>
            </execution>
        </executions>
    </plugin>

For anyone else struggling with this using webflux on Gradle, I managed to get a barebones project working that provides access to the UI and api-docs. For me you needed this line in the plugins section

id 'java-library'

(along with the spring boot framework plugin)

EDIT: It seems like the above line is not necessary? Unsure, but if you're trying this, it should also work without java-library.

and you (should) only need these two dependencies

    implementation 'org.springframework.boot:spring-boot-starter-webflux:3.1.4'
    implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.1.0'

Gradle version that I used is 8.3

If you're able to hit


Then that's a good sign.

You can find an example project I made below

2

You also need to add this annotation to your SpringBootApp main class: @OpenAPIDefinition

@SpringBootApplication
@OpenAPIDefinition
class MyApplication

For Spring Security support use the Below dependency

implementation("org.springdoc:springdoc-openapi-starter-common:2.1.0")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0")

from

I got the same error and solved it by changing the following dependency

from : implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'

to : implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'

Also please have in mind this compatibility matrix for spring boot:

Compatibility matrix

I would also advice that you delete the cookies of your browser for the host you are trying to access swagger on!

in my case, you have to add below lines in application.yml:
springdoc: api-docs: path: /api-docs swagger-ui: path: /swagger-ui.html enabled: true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.