spring Whitelabel Error Page Swagger,此应用程序没有明确的/errorMap,因此您将此视为回退swagger 2:3.0.0-SNAPSHOT

wwtsj6pe  于 2024-01-05  发布在  Spring
关注(0)|答案(4)|浏览(160)

尝试在Sping Boot 2.3.1中配置Swagger。

Gradle配置

  1. repositories {
  2. mavenCentral()
  3. maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
  4. }
  5. dependencies {
  6. implementation 'org.springframework.boot:spring-boot-starter-data-rest'
  7. testImplementation('org.springframework.boot:spring-boot-starter-test') {
  8. exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
  9. }
  10. implementation "io.springfox:springfox-boot-starter:3.0.0-SNAPSHOT"
  11. compile('io.springfox:springfox-swagger2:3.0.0-SNAPSHOT')
  12. compile('io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT')
  13. }

字符串

Swagger配置

  1. @Configuration
  2. @EnableSwagger2
  3. public class ApplicationSwaggerConfig {
  4. @Bean
  5. public Docket employeeApi() {
  6. return new Docket(DocumentationType.SWAGGER_2)
  7. .select()
  8. .apis(RequestHandlerSelectors.any())
  9. .paths(PathSelectors.any())
  10. .build()
  11. .apiInfo(getApiInfo());
  12. }
  13. //create api metadata that goes at the top of the generated page
  14. private ApiInfo getApiInfo() {
  15. return new ApiInfoBuilder()
  16. .title("Employee API")
  17. .version("1.0")
  18. .description("API for managing employees.")
  19. .contact(new Contact("Craig Golightly", "http://globomantics.com", "[email protected]"))
  20. .license("Apache License Version 2.0")
  21. .build();
  22. }
  23. }

控制器

  1. @RestController
  2. public class TestController {
  3. @RequestMapping(value = "/HelloWorld", method = RequestMethod.GET)
  4. public String HelloWorld(){
  5. return "Hello World";
  6. }
  7. }

申请

  1. @SpringBootApplication
  2. public class MeroRentalRestApiApplication {
  3. public static void main(String[] args) {
  4. SpringApplication.run(MeroRentalRestApiApplication.class, args);
  5. }
  6. }

错误

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


的数据
以下是软件包参考

xqkwcwgp

xqkwcwgp1#

能解决问题
删除下面的依赖项

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

字符串
移除swagger 2标记

  1. @EnableSwagger2


导航URL为http://localhost:8080/swagger-ui/index.html
参考https://github.com/springfox/springfox/issues/3070

pkln4tw6

pkln4tw62#

在spring Boot 中,它的工作原理是简单地添加this,不需要其他依赖项:

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-boot-starter</artifactId>
  4. <version>3.0.0</version>
  5. </dependency>

字符串
URL是/swagger-ui/

gzjq41n4

gzjq41n43#

在我的pom.xml中添加这两个依赖项解决了这个问题

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-swagger2</artifactId>
  4. <version>2.9.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.springfox</groupId>
  8. <artifactId>springfox-swagger-ui</artifactId>
  9. <version>2.9.2</version>
  10. </dependency>

字符串
我希望它能帮助一些人

eivnm1vs

eivnm1vs4#

如果你使用的是swagger 2,在这种情况下,url会被更新。
http://localhost:8080/swagger-ui. html/
http://localhost:8080/swagger-ui/index.html
如果你使用的是spring Boot ,请将这两个依赖项添加到swagger 2的pom中。

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-boot-starter</artifactId>
  4. <version>3.0.0</version>
  5. </dependency>

字符串

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-swagger-ui</artifactId>
  4. <version>3.0.0</version>
  5. </dependency>


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

展开查看全部

相关问题