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

 ̄綄美尐妖づ 提交于 2020-07-23 06:25:10

问题


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", "craig@globomantics.com"))
                .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).

Here is the package reference


回答1:


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



来源:https://stackoverflow.com/questions/62754998/whitelabel-error-page-swagger-this-application-has-no-explicit-mapping-for-err

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!