在我的项目中实施 swagger 时,我面临这个问题。
这是我的 build.gradle 文件和我的 swagger 配置文件。
@Configuration
@EnableSwagger2
@EnableWebMvc
public class MisToolSwaggerConfig {
@Beanpublic Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select() .apis(RequestHandlerSelectors.basePackage("co.oasys.mis.tool.restapi")).paths(PathSelectors.any())
.build();
}
当我运行我的应用程序时,显示此错误
适用于 Spring Boot 3
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.4</version>
</dependency>
@Configuration
public class OpenAPIConfig {
@Bean
public OpenAPI registrationOpenAPI() {
return new OpenAPI()
.info(new Info().title("Your API Title")
.description("Your API Description")
.version("1.0"));
}
}
#OpenAPI Properties
springdoc:
api-docs:
path: /api-docs
swagger-ui:
path: /swagger-ui.html
enabled: true
尝试将此行添加到您的 application.properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
这是一个工作 swagger 配置文件的示例
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
private static final String TITLE = "Flight API";
private static final String DESCRIPTION = "Descripcion API Flight";
private static final String BASE_PACKAGE = "com.hiberus.flight.controller";
private static final String VERSION = "v1";
@Bean
public Docket swagger() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
.build()
.forCodeGeneration(true)
.apiInfo(new ApiInfoBuilder().title(TITLE).description(DESCRIPTION).version(VERSION).build());
}
}