why Swagger UI is not working in Spring Boot 3.0 version?
Asked Answered
S

6

12

I'm trying to run my Spring boot application which is based on version 3.0 with swagger UI and I'm getting a lot of exceptions I have explored many sources like youtube and documentation but I'm unable to find the solution.

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

if any one can share the solution it will be very nice.

Sherrillsherrington answered 21/12, 2022 at 12:26 Comment(2)
already answered - #46152040Moyers
Does this answer your question? Added Springfox Swagger-UI and it's not working, what am I missing?Moyers
P
16

SpringFox is for all intents and purposes dead / abandoned project. It hasn't has a release since July 2020, note the 3.0.0 is their support for Spring Boot 2.0.0. The breaking API changes, if you haven't already been affected by them in prior releases, have finally broken it for you with the latest Spring Boot 3.0.0 which introduces significant breaking changes in Spring Framework and Spring Boot.

One of which is a change to how Autoconfiguration's must be registered in Spring Boot. The old method was deprecated in 2.7.0 and removed in 3.0.0. Springfox will not work without manually creating the beans required, and this is assuming that there is not more breaking changes in the other Spring components it uses.

There is an alternative in the form of SpringDoc which gives you the same functionality of Springfox's implementation of the OpenAPI / Swagger spec and more.

There is a simple migration guide to move from Springfox to SpringDoc.

Pearse answered 21/12, 2022 at 12:36 Comment(3)
I'm using SpringDoc already and Springboot 3 broke that for me as wellWhoever
@Whoever hey are you able to find a fix? I am also not able to open swagger ui anymore. I am using SpringDoc and Springboot 3.Estimate
@AmjadAziz Hi yes I did. It turned out to be a simple fix of changing the pom dependency. SRC: #74702238Whoever
H
13

for spring boot 3 use

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.1.0</version>
 </dependency>
Heterochromatic answered 4/4, 2023 at 6:49 Comment(1)
Incase this helps. I was getting a 401 rather than 404 or anything but changing the dependency to this, fixed it.Categorical
H
1

I was using the latest version of spring boot which was 3.2.2 thus I choose the latest version of swagger 2.2.0 but It doesn't work . Choose the below version .It'll run seamless

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.1.0</version>
    </dependency>
Hairdo answered 4/2 at 5:14 Comment(0)
S
1

Solution for Swagger UI with Spring Boot 3.0 using springdoc-openapi

If you are facing issues with springfox and Swagger UI in your Spring Boot 3.0 application, switch to using springdoc-openapi:

Add the springdoc-openapi dependency to your pom.xml file:

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

Configure a custom path for Swagger UI in your application.properties or application.yml file:

Swagger UI custom path

springdoc.swagger-ui.path=/swagger-ui.html

This will set the Swagger UI endpoint to "/swagger-ui.html". Adjust it according to your preferences.

Now, you should be able to access Swagger UI at the specified path and document your APIs easily.

For more details and configuration options, refer to the springdoc-openapi documentation.

Shoe answered 15/2 at 15:8 Comment(0)
T
-1
<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.1.0</version>
 </dependency>
package com.surya;


import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class SpringDocConfig {

  
    @Bean
    public GroupedOpenApi controllerApi() {
        return GroupedOpenApi.builder()
                .group("controller-api")
                .packagesToScan("com.surya.controller") // Specify the package to scan
                .build();
    }



}
Truesdale answered 22/8, 2023 at 10:25 Comment(2)
Please read How to Answer and edit your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post.Pepsin
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Feder
R
-1

I had sililar issue at one on the code base. There in the prior implementation which was using Spring 2.2.4, WebMVCConfig was overriden to achieve business goals.

In Spring 3.0.4, Overidden WebMVCConfig class was extended by delegatingwebmvcconfiguration class. And olf addresourcehandler method was kept as is.

In the addresourcehandler(), super.addresourcehandler(registry) was not called. It resulted in incomplete set of REGISTRY missing SwaggerCOnfigProperties needed badly at runtime. After adding 'super.addresourcehandler(registry)' call, configuration got completed correctly..

I am adding this comment as I have not seen this flavour in any of questions or answers or comments.

Rifkin answered 18/10, 2023 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.