美文网首页
Springboot3 配置Swargger3.0版本

Springboot3 配置Swargger3.0版本

作者: JD2017 | 来源:发表于2024-11-06 17:02 被阅读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 {
    @Bean
    public OpenAPI springOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("Spring Boot 3 API")
                        .description("API文档描述")
                        .version("v1.0"));
    }

}

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

http://localhost:8080/swagger-ui.html
image.png
springdoc-openapi参考文献地址

相关文章

网友评论

      本文标题:Springboot3 配置Swargger3.0版本

      本文链接:https://www.haomeiwen.com/subject/dpytjjtx.html