Springboot3整合Swagger报错或不显示接口:Type javax.servlet.http.HttpServletRequest not present
4、改配置(我是application.yml,如果上面有spring就在spring下面加配置)能访问Swagger但是不显示接口的跳到4。
·
能访问Swagger但是不显示接口的跳到4
1、删依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2、加依赖
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.15</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
3、改配置类
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@EnableWebMvc
public class MySwaggerConfig {
@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("SpringShop API")
.description("Spring shop sample application")
.version("v0.0.1")
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
.externalDocs(new ExternalDocumentation()
.description("SpringShop Wiki Documentation")
.url("https://springshop.wiki.github.org/docs"));
}
}
4、改配置(我是application.yml,如果上面有spring就在spring下面加配置)
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
5、访问http://localhost:9999/swagger-ui/index.html
注:想要在Swagger上添加中文注解,那么Controller层的注解方式都要改
@Api(tags = "")
改为
@Tag(name = "用户管理")
@ApiModel(value="", description="")
改为
@Schema(name="", description="")
@ApiModelProperty(value = "", required = true)
改为
@Schema(name= "", description = "", required = true)
@ApiOperation(value = "", notes = "")
改为
@Operation(summary = "用户登录", description = "")
@ApiParam 改为 @Parameter
@ApiResponse(code = 404, message = "")
改为
@ApiResponse(responseCode = "404", description = "")
参考致谢:
swagger3.x 不显示接口 No operations defined in spec!_swagger3 no operations defined in spec!-CSDN博客
更多推荐
已为社区贡献1条内容
所有评论(0)