Looks like you want to use Springfox3. If yes, then try the following changes.

Remove springfox-swagger2 and springfox-swagger-ui and add below dependency in pom.xml

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

SwaggerConfig - remove @EnableSwagger2 annotation

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.aluno"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(metaInfo());
    }

    private ApiInfo metaInfo() {

        ApiInfo apiInfo = new ApiInfo(
                "Cursos API REST",
                "API REST de registro de alunos.",
                "1.0",
                "Terms of Service",
                new Contact("Romulo Sorato", "https://www.linkedin.com/in/r%C3%B4mulo-sorato-domingos-a6524437/",
                        "[email protected]"),
                "Apache License Version 2.0",
                "https://www.apache.org/licesen.html", new ArrayList<>()
        );

        return apiInfo;
    }
}

For this version, URL of UI has been changed as shown below:

http://localhost:8080/swagger-ui/index.html

If you want to use older version then just use version 2.9.2 (works perfectly fine for me). No other changes required in your config file or UI's URL.

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
Answer from HarishVijayamohan 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 - In this case, it won’t matter if we use SpringDoc or Springfox: @Controller public class SwaggerController { @RequestMapping("/myproject") public String getRedirectUrl() { return "redirect:swagger-ui/"; } } In this article, we learned how to change the default swagger-ui URL for REST API documentation using Springfox and SpringDoc.
🌐
Springfox
springfox.github.io › springfox › docs › current
Springfox Reference Documentation
In this scenario, Springfox will not correctly generate and expose the Swagger UI endpoint (/swagger-ui.html) if @EnableWebMvc is present in the application. Caveat to using the library is that it depends on Jackson for serialization, more importantly the ObjectMapper. A good example of where this breaks down is the following issue when using Gson serialization · By default the swagger service descriptions are generated at the following urls
Top answer
1 of 2
11

Looks like you want to use Springfox3. If yes, then try the following changes.

Remove springfox-swagger2 and springfox-swagger-ui and add below dependency in pom.xml

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

SwaggerConfig - remove @EnableSwagger2 annotation

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.aluno"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(metaInfo());
    }

    private ApiInfo metaInfo() {

        ApiInfo apiInfo = new ApiInfo(
                "Cursos API REST",
                "API REST de registro de alunos.",
                "1.0",
                "Terms of Service",
                new Contact("Romulo Sorato", "https://www.linkedin.com/in/r%C3%B4mulo-sorato-domingos-a6524437/",
                        "[email protected]"),
                "Apache License Version 2.0",
                "https://www.apache.org/licesen.html", new ArrayList<>()
        );

        return apiInfo;
    }
}

For this version, URL of UI has been changed as shown below:

http://localhost:8080/swagger-ui/index.html

If you want to use older version then just use version 2.9.2 (works perfectly fine for me). No other changes required in your config file or UI's URL.

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
2 of 2
1

could you please try this, it works for me

@Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()                                       
                  .apis(RequestHandlerSelectors.basePackage("com.aluno.controller"))
                  .paths(PathSelectors.any())                   
                  .build();
    }

could you please check, these dependencies are added

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
🌐
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
🌐
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
🌐
GitHub
github.com › springfox › springfox › issues › 1406
How can we change the swagger-ui access URL? · Issue #1406 · springfox/springfox
July 21, 2016 - <dependency> <groupId>io.sprin...080//rest/swagger-ui.html · So i want to change that URL to : http://localhost:8080/swagger or http://localhost:8080//swagger....
Author   prathap413
Top answer
1 of 3
10

UPD: Springfox is abandoned

Springfox Swagger had always been kinda dirty solution with a lot of unclearness and bugs, but by now (2021 Q4) it hadn't been updated for more than a year.

The final straw was the fact that Springfox Swagger 3.0 doesn't work anymore with Spring Boot 2.6.x.

So, if you reading this, please, consider switching over to https://springdoc.org/ instead.

It's a pretty straightforward conversion and they do a great job of documenting it. https://springdoc.org/#migrating-from-springfox.

Original answer

I've found a working solution for Springfox 3.0.0 here:

springfox:
  documentation:
    swaggerUi:
      baseUrl: /documentation
    openApi:
      v3:
        path: /documentation/v3/api-docs
    swagger:
      v2:
        path: /documentation/v2/api-docs

Configuration above will change base-path for Swagger endpoints to /documentation without any redirects and other crutches.

It is sad that these configurations is missing in the docs tho.

2 of 3
6

Try this configuration class.

@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {

  @Bean
  public Docket productApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select().apis(RequestHandlerSelectors.basePackage(""my.favorite.package""))
                        .paths(regex(PathSelectors.any()))
        .build();

  }

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true);
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
    registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/documentation/**").addResourceLocations("classpath:/META-INF/resources/");
  }


}
🌐
Maven Repository
mvnrepository.com › artifact › io.springfox › springfox-swagger-ui
Maven Repository: io.springfox » springfox-swagger-ui
July 14, 2020 - Home » io.springfox » springfox-swagger-ui · JSON API documentation for spring based applications · LicenseApache 2.0 · Tagsspringopenapiuiswaggerapi · Ranking · #20877in MvnRepository · HomePage https://github.com/springfox/springfox 🔍 Inspect URL ·
🌐
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 - @Configuration @EnableSwagger2 public class SpringFoxConfig { } Additionally, without Spring Boot, we don’t have the luxury of auto-configuration of our resource handlers. Swagger UI adds a set of resources that we must configure as part of a class that extends WebMvcConfigurerAdapter and is annotated with @EnableWebMvc:
Find elsewhere
🌐
Maven Repository
mvnrepository.com › artifact › io.springfox › springfox-swagger-ui › 3.0.0
Maven Repository: io.springfox » springfox-swagger-ui » 3.0.0
July 14, 2020 - Home » io.springfox » springfox-swagger-ui » 3.0.0 · JSON API documentation for spring based applications · LicenseApache 2.0 · Tagsspringopenapiuiswaggerapi · HomePage https://github.com/springfox/springfox 🔍 Inspect URL · Links · DateJul 14, 2020 ·
Published   Jul 14, 2020
Version   3.0.0
Top answer
1 of 6
22

From: http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version

there are things need to do:

1. add springfox-boot-starter to POM , remove old dependencies from POM: springfox-swagger2 and springfox-swagger-ui

    <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
</dependency>

2. Remove the @EnableSwagger2 annotations

@Configuration
// remove @EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).select()
        .apis(RequestHandlerSelectors.basePackage(UserManagementImpl.class.getPackage().getName()))
        .paths(PathSelectors.any()).build();
    }
}

3. using @RequestPart("files") on request

@ApiOperation(value = "files", notes = "upload user emails from CSV and email content from json and send out")
    @PostMapping(path = "/users/uploadUserEmailsAndSend", consumes = { "multipart/form-data" })
    @ResponseBody
    ResponseEntity<UploadUsersResDTO> uploadUserEmailsAndSend(@RequestPart("files") MultipartFile[] filesUpload){

    CSVParser csvParser = null;
    BufferedReader fileEmailsReader = null;
    BufferedReader fileEmailMessageReader = null;
    MultipartFile fileCSV = null;
    MultipartFile fileJson = null;

    try {
        if (filesUpload[0].getOriginalFilename().toLowerCase().endsWith("csv")) {
            fileCSV = filesUpload[0];
            fileJson = filesUpload[1];
        } else {
            fileCSV = filesUpload[1];
            fileJson = filesUpload[0];
        }
        // more codes ....
}

4. access swagger at: http://localhost:8080/swagger-ui/

5. Last: you should move to OpenAPI (https://springdoc.org/)

OpenAPI is top on swagger, so if you are using Spring boot, the OpenAPI configuration is much simpler than Springfox.

2 of 6
4

Quoted from http://springfox.github.io/springfox/docs/current/#changes-in-swagger-ui

swagger-ui location has moved from http://host/context-path/swagger-ui.html to http://host/context-path/swagger-ui/index.html OR http://host/context-path/swagger-ui/ for short. This makes it work much better with pulling it as a web jar and turning it off using configuration properties if not needed.

for maven

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

for gradle

dependencies {
    compile 'io.springfox:springfox-swagger-ui:3.0.0'
}
🌐
GitHub
github.com › springfox › springfox › issues › 4012
Change swagger-ui.html location without affecting APIs · Issue #4012 · springfox/springfox
June 3, 2022 - springfox: documentation: swaggerUi: baseUrl: /customDir openApi: v3: path: /customDir/v3/api-docs swagger: v2: path: /customDir/v2/api-docs · Unfortunately, when attempting this fix, I get an "Unable to infer base url" popup that keeps popping up no matter what I type:
Author   jasonfilippou
🌐
Maven Central
central.sonatype.com › artifact › io.springfox › springfox-swagger-ui
Maven Central: io.springfox:springfox-swagger-ui
Discover springfox-swagger-ui in the io.springfox namespace. Explore metadata, contributors, the Maven POM file, and more.
🌐
Springfox
springfox.github.io › springfox › docs › snapshot
Springfox Reference Documentation - GitHub Pages
October 14, 2020 - In this scenario, Springfox will not correctly generate and expose the Swagger UI endpoint (/swagger-ui.html) if @EnableWebMvc is present in the application. Caveat to using the library is that it depends on Jackson for serialization, more importantly the ObjectMapper. A good example of where this breaks down is the following issue when using Gson serialization · By default the swagger service descriptions are generated at the following urls
🌐
Rip Tutorial
riptutorial.com › setup springfox using swagger-ui in spring-boot
swagger Tutorial => Setup springfox using swagger-ui in spring-boot
Add the dependencies for swagger2 and swagger-ui in your pom.xml · <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.0</version> </dependency> Add the annotation @EnableSwagger2 to your @SpringBootApplication annotated main class and create a swagger Docket bean within this (or any other) configuration class.
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.