swagger3.0整合springboot

本文介绍了如何将Swagger3.0整合到SpringBoot项目中,包括引入高版本依赖、配置步骤和访问地址。同时,详细解析了Swagger2.0的注解使用,如@Api、@ApiOperation等,用于API的文档化和参数说明。
摘要由CSDN通过智能技术生成

1.引入依赖jar

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

注意:

1.尽量不要引入低版本的(例如2.2.2),会跟springbootjar包冲突。

2.如果springfox相关的jar包都是3.0.0的,(例如springfox-spring-web),上面两个一定要引入3.0.0。

2.增加config

@Configuration
@EnableSwagger
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.cloudnative.module.template.interfaces.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值