I had a similar task for Spring Boot 2.5.6 and springdoc-openapi-webflux-ui 1.5.12. I've found several possible solutions for myself. Maybe it will be helpful for somebody else.


Set springdoc.swagger-ui.path directly

The straightforward way is to set property springdoc.swagger-ui.path=/custom/path. It will work perfectly if you can hardcode swagger path in your application.


Override springdoc.swagger-ui.path property

You can change default swagger-ui path programmatically using ApplicationListener<ApplicationPreparedEvent>. The idea is simple - override springdoc.swagger-ui.path=/custom/path before your Spring Boot application starts.

@Component
public class SwaggerConfiguration implements ApplicationListener<ApplicationPreparedEvent> {

    @Override
    public void onApplicationEvent(final ApplicationPreparedEvent event) {
        ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
        Properties props = new Properties();
        props.put("springdoc.swagger-ui.path", swaggerPath());
        environment.getPropertySources()
                .addFirst(new PropertiesPropertySource("programmatically", props));
    }

    private String swaggerPath() {
        return "/swagger/path"; //todo: implement your logic here.
    }
}

In this case, you must register the listener before your application start:

@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "APIs", version = "0.0.1", description = "APIs v0.0.1"))
public class App {
    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(App.class);
        application.addListeners(new SwaggerConfiguration());
        application.run(args);
    }
}

Redirect using controller


You can also register your own controller and make a simple redirect (the same as what you suggest, but in my case, I need to use the WebFlux approach):

@RestController
public class SwaggerEndpoint {

    @GetMapping("/custom/path")
    public Mono<Void> api(ServerHttpResponse response) {
        response.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
        response.getHeaders().setLocation(URI.create("/swagger-ui.html"));
        return response.setComplete();
    }
}

The problem with such an approach - your server will still respond if you call it by address "/swagger-ui.html".

Answer from Volodya Lombrozo on Stack Overflow
🌐
Baeldung
baeldung.com › home › spring › spring boot › change swagger-ui url prefix
Change Swagger-UI URL prefix - Spring Boot
May 11, 2024 - Learn how to change the Swagger-UI URL prefix when using Springfox and how to set up the REST API documentation using OpenAPI 3.0 with redirections.
Discussions

java - How to make default url to be viewed in browser in spring boot? - Stack Overflow
Every time when I distribute or deploy to third party or any other person, I have to always mention the swagger url for the user to go through the REST end-points. My question is how to make a default redirected url in case of spring boot so that it should redirect to swagger-ui.html automatically. More on stackoverflow.com
🌐 stackoverflow.com
How to specify api docs url for swagger ui in spring boot (open api v3)? - Stack Overflow
I have a spring boot application with open-api 3 that is deployed in Kubernetes (spring-boot-starter-parent 2.2.4.RELEASE). The rest endpoints are accessible through ingress, so URL is something li... More on stackoverflow.com
🌐 stackoverflow.com
Configuring Swagger UI with Spring Boot - Stack Overflow
I am trying to configure Swagger UI with my Spring boot application. Although the v2/api-docs seems to be loading properly, the http://localhost:8080/swagger-ui.html does not load my annotated REST... More on stackoverflow.com
🌐 stackoverflow.com
spring boot - How to change swagger-ui.html default path - Stack Overflow
You can change default swagger-ui path programmatically using ApplicationListener. The idea is simple - override springdoc.swagger-ui.path=/custom/path before your Spring Boot application starts. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 3
3

I had a similar task for Spring Boot 2.5.6 and springdoc-openapi-webflux-ui 1.5.12. I've found several possible solutions for myself. Maybe it will be helpful for somebody else.


Set springdoc.swagger-ui.path directly

The straightforward way is to set property springdoc.swagger-ui.path=/custom/path. It will work perfectly if you can hardcode swagger path in your application.


Override springdoc.swagger-ui.path property

You can change default swagger-ui path programmatically using ApplicationListener<ApplicationPreparedEvent>. The idea is simple - override springdoc.swagger-ui.path=/custom/path before your Spring Boot application starts.

@Component
public class SwaggerConfiguration implements ApplicationListener<ApplicationPreparedEvent> {

    @Override
    public void onApplicationEvent(final ApplicationPreparedEvent event) {
        ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
        Properties props = new Properties();
        props.put("springdoc.swagger-ui.path", swaggerPath());
        environment.getPropertySources()
                .addFirst(new PropertiesPropertySource("programmatically", props));
    }

    private String swaggerPath() {
        return "/swagger/path"; //todo: implement your logic here.
    }
}

In this case, you must register the listener before your application start:

@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "APIs", version = "0.0.1", description = "APIs v0.0.1"))
public class App {
    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(App.class);
        application.addListeners(new SwaggerConfiguration());
        application.run(args);
    }
}

Redirect using controller


You can also register your own controller and make a simple redirect (the same as what you suggest, but in my case, I need to use the WebFlux approach):

@RestController
public class SwaggerEndpoint {

    @GetMapping("/custom/path")
    public Mono<Void> api(ServerHttpResponse response) {
        response.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
        response.getHeaders().setLocation(URI.create("/swagger-ui.html"));
        return response.setComplete();
    }
}

The problem with such an approach - your server will still respond if you call it by address "/swagger-ui.html".

2 of 3
2

Apparantly the library integrates natively only with spring-boot applications like you mentioned in your comment. If you want to use spring, it's possible but the integration details aren't documented, because it really depends on the version/module and the nature of you spring application.

You can check the FAQ to see if it answers your questions.

There are some more answers here on SO.

🌐
Medium
medium.com › @AlexanderObregon › adding-swagger-ui-to-document-spring-boot-apis-67e6b42038d9
Adding Swagger UI to Document Spring Boot APIs | Medium
May 25, 2025 - When you hit /swagger-ui.html, Springdoc's SwaggerWelcome bean simply redirects you to the real page at /swagger-ui/index.html, so either URL works. You don’t have to register anything manually, but here’s a quick example of what Spring Boot wires up during startup:
🌐
Medium
apu-pradhan.medium.com › how-to-set-up-swagger-in-spring-boot-68b3fe862a0d
How to Set Up Swagger in Spring Boot | by Apu | Medium
November 18, 2024 - Use the correct URL: /swagger-ui/index.html for newer versions. Ensure your controllers are located in packages scanned by Spring Boot.
🌐
SpringDoc
springdoc.org
OpenAPI 3 Library for spring-boot
This will automatically deploy ... swagger-ui jars · The Swagger UI page will then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url ...
🌐
Apidog
apidog.com › blog › swagger-ui-url
How to Change Swagger UI URL Defauth Path
February 5, 2026 - The Swagger UI URL corresponds to the endpoint where you serve your OpenAPI specification JSON file. This means that you need to provide a web address that points to the location of your OpenAPI JSON file.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › advance java › spring-boot-enabling-swagger2
Spring Boot - Enabling Swagger2 - GeeksforGeeks
July 23, 2025 - Interactive Exploration for Endpoints: Developers can view and try your APIs directly by visiting the swagger default URL i.e. localhost:8080/swagger-ui.html · Easy Configuration: Swagger2 can be easily integrated into Spring Boot applications ...
🌐
Medium
medium.com › @akshitaswami248 › swagger-configuration-in-spring-boot-application-8558492df54b
Swagger Configuration in Spring Boot Application | by Akshitaswami | Medium
July 10, 2023 - # Enable Swagger UI springfox.documentation.swagger-ui.enabled=true · Step 4: Test Swagger Start your Spring Boot application, and you should be able to access the Swagger UI at “http://localhost:8080/swagger-ui.html”. It will display the ...
🌐
Bell Software
bell-sw.com › blog › documenting-rest-api-with-swagger-in-spring-boot-3
How to use Swagger with Spring Boot
To work with Swagger, we need the springdoc-api library that helps to generate OpenAPI-compliant API documentation for Spring Boot projects. The library supports Swagger UI and other useful features such as OAuth2 and GraalVM Native Image.
🌐
BezKoder
bezkoder.com › home › spring boot + swagger 3 example (with openapi 3)
Spring Boot + Swagger 3 example (with OpenAPI 3) - BezKoder
January 25, 2024 - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.15' Run Spring Boot project. Open browser with url: http://localhost:8080/swagger-ui/index.html
🌐
Baeldung
baeldung.com › home › rest › setting up swagger 2 with a spring rest api using springfox
Setting Up Swagger 2 with a Spring REST API | Baeldung
November 12, 2025 - Note how the name we used here in the reference — spring_oauth — syncs up with the name we used previously in the SecurityScheme. Now that we have everything set up and ready to go, let’s take a look at our Swagger UI and try access the Foo API.
🌐
SpringDoc
springdoc.org › getting-started.html
Getting Started
September 7, 2025 - 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 http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available ...
Top answer
1 of 7
8

I had this issue today and fixed it by matching up the versions of my springfox-swagger2 and springfox-swagger-ui dependencies:

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

There's very little other code to just get it up and running. One simple config class:

@Configuration
@EnableSwagger2
class SwaggerConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.foo.samples.swaggersample"))
                .paths(PathSelectors.any())
                .build();
    }

}

And my application.properties

# location of the swagger json
springfox.documentation.swagger.v2.path=/swagger.json

(This is in Spring Boot).

2 of 7
2

Statement : Generate Swagger UI for the listing of all the REST APIs through Spring Boot Application.

Follow the below steps to generate the Swagger UI through Spring Boot application:

1. Add following dependency in pom.xml –

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>

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

2. Add the following piece of code in your main application class having the @EnableSwagger2 annotation.

    @EnableSwagger2
    @SpringBootApplication
    public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()  
           .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
           .paths(PathSelectors.any()).build().pathMapping("/")
           .apiInfo(apiInfo()).useDefaultResponseMessages(false);
    }

    @Bean
    public ApiInfo apiInfo() {
        final ApiInfoBuilder builder = new ApiInfoBuilder();
        builder.title("My Application API through Swagger UI").version("1.0").license("(C) Copyright Test")
        .description("List of all the APIs of My Application App through Swagger UI");
        return builder.build();
        }
    }

3. Add the below RootController class in your code to redirect to the Swagger UI page. In this way, you don’t need to put the dist folder of Swagger-UI in your resources directory.

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    @Controller
    @RequestMapping("/")
    public class RootController {
        @RequestMapping(method = RequestMethod.GET)
        public String swaggerUi() {
            return "redirect:/swagger-ui.html";
        }
    }

4. Being the final steps, add the @Api and @ApiOperation notation in all your RESTControllers like below –

    import static org.springframework.web.bind.annotation.RequestMethod.GET;
    import org.springframework.http.HttpStatus;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseStatus;
    import org.springframework.web.bind.annotation.RestController;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;

    @RestController
    @RequestMapping("/hello")
    @Api(value = "hello", description = "Sample hello world application")
    public class TestController {

        @ApiOperation(value = "Just to test the sample test api of My App Service")
        @RequestMapping(method = RequestMethod.GET, value = "/test")
        // @Produces(MediaType.APPLICATION_JSON)
        public String test() {
            return "Hello to check Swagger UI";
        }

        @ResponseStatus(HttpStatus.OK)
        @RequestMapping(value = "/test1", method = GET)
        @ApiOperation(value = "My App Service get test1 API", position = 1)
        public String test1() {
            System.out.println("Testing");
            if (true) {
                return "Tanuj";
            }
            return "Gupta";
        }
    }

Now your are done. Now to run your Spring Boot Application, go to browser and type localhost:8080. You will see Swagger UI having all the details of your REST APIs.

Happy Coding.
The source code of the above implementation is also on my blog if you feel like checking it out.

🌐
DEV Community
dev.to › olymahmud › integrating-openapi-documentation-and-swagger-ui-in-spring-boot-38p6
Integrating OpenAPI Documentation and Swagger UI in Spring Boot - DEV Community
December 20, 2024 - That's it. We have integrated OpenAPI Docs and Swagger UI into our Spring Boot project. Open a browser, and enter the following URL: http://localhost:8080/swagger-ui/index.html
🌐
Nodalpoint
nodalpoint.com › home › blog › configure swaggerui in a springboot application
Configure SwaggerUI in a SpringBoot application - Nodalpoint
February 21, 2025 - Here’s how you can configure Swagger UI for your Spring Boot API. In your pom.xml, include the following dependencies to integrate Springdoc OpenAPI: ... For any other SpringBoot version please check the related compatibility. Define a Spring Bean to set up the OpenAPI configuration, customizing details such as the API’s title, description, version, and licensing information: ... If your application operates behind a reverse proxy that modifies URLs, implement the following steps: