温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在Spring Boot应用中集成Swagger文档

发布时间:2024-05-29 16:52:05 来源:亿速云 阅读:79 作者:小樊 栏目:web开发

要在Spring Boot应用中集成Swagger文档,可以按照以下步骤进行操作:

  1. 添加Swagger依赖:在pom.xml文件中添加Swagger依赖。可以使用以下依赖:
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>
  1. 配置Swagger:创建一个配置类,用于配置Swagger。可以使用以下代码:
@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()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot REST API")
                .description("APIs for Spring Boot application")
                .version("1.0")
                .build();
    }
}
  1. 启动应用:启动Spring Boot应用,并访问http://localhost:8080/swagger-ui/,即可查看Swagger文档。

通过以上步骤,就可以在Spring Boot应用中集成Swagger文档,方便进行API文档的查看和测试。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI