Whitelabel Error Page Swagger, This application has no explicit mapping for /error, so you are seeing this as a fallback swagger2:3.0.0-SNAPSHOT
Asked Answered
L

4

8

Trying to configure swagger in spring boot 2.3.1.

Gradle Config

repositories {
    mavenCentral()
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation "io.springfox:springfox-boot-starter:3.0.0-SNAPSHOT"
    compile('io.springfox:springfox-swagger2:3.0.0-SNAPSHOT')
    compile('io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT')
}

Swagger Config

@Configuration
@EnableSwagger2
public class ApplicationSwaggerConfig {
    @Bean
    public Docket employeeApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .apiInfo(getApiInfo());
    }

    //create api metadata that goes at the top of the generated page
    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("Employee API")
                .version("1.0")
                .description("API for managing employees.")
                .contact(new Contact("Craig Golightly", "http://globomantics.com", "[email protected]"))
                .license("Apache License Version 2.0")
                .build();
    }
}

Controller

@RestController
public class TestController {
    @RequestMapping(value = "/HelloWorld", method = RequestMethod.GET)
    public String HelloWorld(){
        return "Hello World";
    }
}

Application

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

Error

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 06 21:19:55 AEST 2020
There was an unexpected error (type=Not Found, status=404).

enter image description here

Here is the package reference enter image description here

Lacilacie answered 6/7, 2020 at 11:24 Comment(4)
What about the api-docs endpoint? Is it available?Dagenham
Same thing with the API-DOC localhost:8080/api/v2/api-docsLacilacie
Is there a server.servlet.context-path property present? If so, try adding the context path to the Swagger urls you're attempting to visit.Prudential
@Prudential After adding server.servlet.contextPath=/swagger-ui.html. I can see { "_links" : { "profile" : { "href" : "localhost:8080/swagger-ui.html/profile" } } }Lacilacie
L
14

Able to solve the problem

Remove the below dependency

compile('io.springfox:springfox-swagger2:3.0.0-SNAPSHOT')
compile('io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT')

Remove the swagger 2 anotation

@EnableSwagger2

The navigation URL is http://localhost:8080/swagger-ui/index.html

Reference https://github.com/springfox/springfox/issues/3070

Lacilacie answered 7/7, 2020 at 17:23 Comment(4)
Solved my problem too.Prau
So glad I came across this answer. I was trying to navigate the UI on localhost:7000/swagger-ui.html instead of localhost:7000/swagger-ui/index.htmlMcandrew
Thanks, in my case I had to add @Profile ("swagger"), to the config.Scad
For me it's working without removing @EnableSwagger2. Same result if I remove it too!Paugh
M
3

In spring boot it works by simply adding this, no other dependencies needed:

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

The url is /swagger-ui/

Mosstrooper answered 16/12, 2020 at 19:26 Comment(3)
That's no different from the previous answer.Katzenjammer
In spring boot it works by simply adding this, no other dependencies needed: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> The url is /swagger-ui/Mosstrooper
Hello and welcome to StackOverflow! It seems you have given some useful information in your comment. If you would please move that into your answer, then remove the part of your answer which is the same as Bossit's, and mention that your answer builds on Bossit's, then this answer will be much higher quality and won't be closed as a duplicateCapitulation
A
1

Adding these 2 dependencies in my pom.xml solved the problem

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

hope it may help someone

Antilogarithm answered 20/10, 2020 at 17:19 Comment(0)
K
1

If you are using swagger 2 in that case the url is updated.

Old url : http://localhost:8080/swagger-ui.html/

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

Add these two dependency to your pom for swagger 2 if you are using spring boot.

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

and

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

Reference : https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

Ketosis answered 13/12, 2023 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.