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.
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.

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
Can't find Swagger UI endpoint
Please take the time to search the repository, if your question has already been asked or answered. What version of the library are you using? 2.8.0 With spring boot. More on github.com
🌐 github.com
71
May 5, 2018
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
Spring boot and Swagger url and startup questions - Stack Overflow
I come from programming in c# and now I have to create a couple of Rest Apis in Spring Boot. Everything is working ok and I can show the API in Swagger with springfox-swagger-ui · But I have two questions that I could not find in Internet · Is there any way to show the url ui in the console ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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 ...
🌐
GitHub
github.com › springfox › springfox › issues › 2396
Can't find Swagger UI endpoint · Issue #2396 · springfox/springfox
May 5, 2018 - However I can't find the UI endpoint. When going to http://localhost:8080/swagger-resources/ I only see: [ { "name": "default", "url": "/v2/api-docs", "swaggerVersion": "2.0", "location": "/v2/api-docs" } ]
Author   nWidart
Find elsewhere
🌐
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:
🌐
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.
🌐
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:
🌐
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.
Top answer
1 of 1
1

I know it's not the question you're asking, but springfox is currently having issues with newer versions of spring. The spring version you're using is still working but as of 2.6 there are bugs, and it looks like the project is not well maintained. Since you're at the beginning of the project, switching is not too hard. You could move to springdocs for example (for migration: https://springdoc.org/#migrating-from-springfox).

With respect to opening a url, there are some good solutions mentioned here: How to open the default webbrowser using java . You could make your swagger url a property and have swagger configure it accordingly, then you can reuse the property to call the url on run-time. If you want to differentiate between environments I'd suggest use profiles. Only open the url in the browser if you start the app on dev environment, and not on prod is then specified by using @Profile("dev"). Create a commandline/application runner with the profile annotation (https://www.tutorialspoint.com/spring_boot/spring_boot_runners.htm), and call the url from there.

That said, combining it gives:

package com.example.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

@Profile("dev")
@Component
public class SwaggerRunner implements ApplicationRunner {

    @Value("${springdoc.swagger-ui.path}")
    private String swaggerPath;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log("\nWelcome to Multi Brow Pop.\nThis aims to popup a browsers in multiple operating systems.\nGood luck!\n");

        final String swaggerUrl = "http://localhost:8000/" + swaggerPath; 
        
        log("We're going to this page: " + swaggerUrl);

        String myOS = System.getProperty("os.name").toLowerCase();
        log("(Your operating system is: " + myOS + ")\n");

        try {
            if (Desktop.isDesktopSupported()) { // Probably Windows
                log(" -- Going with Desktop.browse ...");
                Desktop desktop = Desktop.getDesktop();
                desktop.browse(new URI(swaggerUrl));
            } else { // Definitely Non-windows
                Runtime runtime = Runtime.getRuntime();
                if (myOS.contains("mac")) { // Apples
                    log(" -- Going on Apple with 'open'...");
                    runtime.exec("open " + swaggerUrl);
                } else if (myOS.contains("nix") || myOS.contains("nux")) { // Linux flavours
                    log(" -- Going on Linux with 'xdg-open'...");
                    runtime.exec("xdg-open " + swaggerUrl);
                } else
                    log("I was unable/unwilling to launch a browser in your OS :( #SadFace");
            }
            log("\nThings have finished.\nI hope you're OK.");
        } catch (IOException | URISyntaxException eek) {
            log("**Stuff wrongly: " + eek.getMessage());
        }
    }

    private static void log(String log) {
        System.out.println(log);
    }

}

put springdoc.swagger-ui.path=/custom/path in your application.properties to change the path to your swagger-ui

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.

🌐
GitHub
github.com › springfox › springfox › issues › 2250
How to serve swagger-ui.html at more convenient URL? · Issue #2250 · springfox/springfox
February 12, 2018 - I want to be able to browse to http://localhost:8080/swagger instead of http://localhost:8080/swagger-ui.html to access the UI, but I am struggling to find documentation or examples.
Author   citkane
🌐
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.
🌐
GitHub
github.com › springfox › springfox › issues › 4080
Unable to Access Swagger-UI After Implementing Spring Security Configuration · Issue #4080 · springfox/springfox
February 9, 2024 - However, I'm now facing an issue while trying to incorporate Swagger-UI. Despite configuring both Swagger and Spring Security, I'm unable to access the specific URL "http://localhost:8082/swagger-ui.html".
Author   Krish-Radadiya9
🌐
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 ...
🌐
Springfox
springfox.github.io › springfox › docs › current
Springfox Reference Documentation
If using Spring Boot Web MVC, there is no need to use the @EnableWebMvc annotation, as the framework automatically detects Web MVC usage and configures itself as appropriate. In this scenario, Springfox will not correctly generate and expose the Swagger UI endpoint (/swagger-ui.html) if @EnableWebMvc is present in the application.
🌐
SpringDoc
springdoc.org › getting-started.html
Getting Started
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 ...