集成swagger 简单版

 1、在pom.xml文件添加依赖

   <!--swagger-->

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

  2、创建SwaggerConfiguration配置swagger

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    private static ApiInfo DEFAULT = null;
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2);
    }
}

3、启动项目运行

启动项目后在浏览器中打开http://localhost:8080/swagger-ui.html查看  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,目前最新本的Spring Boot是2.x系列,并没有Spring Boot 3。不过,我可以为您介绍一下Spring Boot 2.x集成Swagger的方法。 Swagger是一个用于构建、文档化和调试RESTful API的开源工具。它可以生成具有交互式文档和代码生成功能的API文档。 要在Spring Boot 2.x中集成Swagger,您需要执行以下步骤: 1. 添加Swagger依赖:在您的项目的pom.xml文件中,添加Swagger的依赖项。例如: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> ``` 2. 创建Swagger配置类:创建一个配置类,用于配置Swagger。例如,创建一个名为SwaggerConfig的类,并添加@Configuration和@EnableSwagger2注解。 ```java @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build(); } } ``` 3. 配置Swagger属性:您可以根据需要配置Swagger的属性,例如API文档的标题、描述等。在上面的配置类中,您可以通过调用Docket对象的方法来设置这些属性。 4. 启动应用程序:启动您的Spring Boot应用程序,并访问http://localhost:8080/swagger-ui.html,您将看到自动生成的API文档界面。 这样,您就成功地将Swagger集成到了Spring Boot 2.x中。您可以使用Swagger的注解来进一步定制和描述您的API,例如@Api、@ApiOperation等。 希望这个简单的介绍对您有帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值