欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > Springboot3 配置Swargger3.0版本

Springboot3 配置Swargger3.0版本

2025/2/24 0:45:48 来源:https://blog.csdn.net/u012874998/article/details/143599151  浏览:    关键词:Springboot3 配置Swargger3.0版本

一、swagger 版本配置,我用的3.0.0

		<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>${swagger.version}</version></dependency>

二、说明:springdoc-openapi v2.6.0 类库说明This library supports:

OpenAPI 3
Spring-boot v3 (Java 17 & Jakarta EE 9)
JSR-303, specifically for @NotNull, @Min, @Max, and @Size.
Swagger-ui
OAuth 2
GraalVM native images

For the integration between spring-boot and swagger-ui, add the library to the list of your project dependencies (No additional configuration is needed)

		<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-starter-webmvc-ui</artifactId><version>2.6.0</version> </dependency>

For custom path of the swagger documentation in HTML format, add a custom springdoc property, in your spring-boot configuration file: .

# swagger-ui custom path
springdoc.swagger-ui.path=/swagger-ui.html

Documentation will be available in yaml format as well, on the following path : /v3/api-docs.yaml
Add the library to the list of your project dependencies. (No additional configuration is needed)

   <dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-starter-webmvc-api</artifactId><version>2.6.0</version></dependency>

This dependency is relevant if you want to generate the OpenAPI description without using the swagger-ui.
For custom path of the OpenAPI documentation in Json format, add a custom springdoc property, in your spring-boot configuration file:

# /api-docs endpoint custom path
springdoc.api-docs.path=/api-docs

三、java文件编写自主配置,可写可不写;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {@Beanpublic OpenAPI springOpenAPI() {return new OpenAPI().info(new Info().title("Spring Boot 3 API").description("API文档描述").version("v1.0"));}}

四、配置好了运行应用,访问地址:

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

在这里插入图片描述

springdoc-openapi参考文献地址

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com