swagger

一、pom文件增加依赖

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

二、编写Swagger2配置类


@EnableSwagger2 //注解启用Swagger2
@Configuration
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为当前包路径(controller层的路径)
                .apis(RequestHandlerSelectors.basePackage("com.aop.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //构建 api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("SpringBoot使用Swagger2构建API")
                //创建人
                .contact(new Contact("Ricky", "http://www.hao123.com", "1964924878@qq.com"))
                //版本号
                .version("1.0")
                //描述
                .description("sawgger 描述")
                .build();
    }
}

三、编写controller测试类


@RestController
public class AppController {

    public static volatile Integer num = 0;
    public static ReentrantLock lock = new ReentrantLock();
    public static volatile LinkedBlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue();

    private RedisAutoConfiguration redisAutoConfiguration;
    private RedisUtil redisUtil;

    @Autowired
    private HelloSender sender;

    public AppController(RedisAutoConfiguration redisAutoConfiguration, RedisUtil redisUtil) {
        this.redisAutoConfiguration = redisAutoConfiguration;
        this.redisUtil = redisUtil;
    }

    @GetMapping("/all")
    public String getTest() throws Exception {
        String msg = "hello";
        return "success";
    }


    @GetMapping("/receive")
    public String receive() throws Exception {
        String msg = "hello";
        return "success";
    }
}

最后通过自己本地配置的端口号加上swagger
http://localhost:90/swagger-ui.html 就可以访问

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值