GOOGLE ADS

jeudi 14 avril 2022

Ajout de Springfox Swagger-UI et ça ne marche pas, qu'est-ce qui me manque?

En suivant les instructions ici :

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

J'ai ajouté ces dépendances à mon projet:

compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"

et configuré SpringFox Swagger comme ceci:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}

mais l'interface utilisateur Swagger ne semble pas être activée. J'ai essayé:


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

  • http://localhost:8080/api/swagger-ui.html

  • http://localhost:8080/v2/api-docs/swagger-ui.html


et tout ce que j'obtiens c'est:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 11 09:43:46 BST 2017
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported

et sur les logs je vois:

2017-09-11 09:54:31.020 WARN 15688 --- [nio-8080-exec-6] o.s.web.servlet.PageNotFound: Request method 'GET' not supported
2017-09-11 09:54:31.020 WARN 15688 --- [nio-8080-exec-6].w.s.m.s.DefaultHandlerExceptionResolver: Resolved exception caused by Handler execution: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

http://localhost:8080/swagger-resources renvoie :

[{"name": "default",
"location": "/v2/api-docs",
"swaggerVersion": "2.0"}]

Qu'est-ce que je rate?


Solution du problème

Springfox 3.0.0 only works with Spring Boot <= 2.6.0-M2 but not with versions above it

Options pour Spring Boot 2.6 M2 < 1. spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER #-> App.properties     - Mais sans actionneur 2. @EnableWebMvc 3. Migrer vers springdoc-openapi-ui- mêmes étapes que io.springfox >= 3.X


























io.springfox >= 2.X

io.springfox >= 3.X

<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-schema</artifactId> <version>2.9.2</version></dependency>
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version></dependency>
browser URL
http://localhost:8080/swagger-ui.html
URL du navigateur
http://localhost:8080/swagger-ui/
http://localhost:8080/swagger-ui/index.html
Doit avoir besoin

mvn clean

Doit avoir besoin

mvn clean

@Configuration@EnableSwagger2
@Configuration@EnableSwagger2

Aucun commentaire:

Enregistrer un commentaire

Comment utiliseriez-vous .reduce() sur des arguments au lieu d'un tableau ou d'un objet spécifique&nbsp;?

Je veux définir une fonction.flatten qui aplatit plusieurs éléments en un seul tableau. Je sais que ce qui suit n'est pas possible, mais...