极致简洁的SpringBoot整合Swagger

极致简洁的SpringBoot整合Swagger

借鉴

借鉴开源项目 com.spring4all.swagger-spring-boot-starter

依赖

<dependency>
	<groupId>com.spring4all</groupId>
	<artifactId>swagger-spring-boot-starter</artifactId>
	<version>1.9.0.RELEASE</version>
</dependency>

使用步骤

在启动类中添加@EnableSwagger2Doc注解

@EnableSwagger2Doc
@SpringBootApplication
public class Bootstrap {

    public static void main(String[] args) {
        SpringApplication.run(Bootstrap.class, args);
    }

}

默认情况下就能产生所有当前Spring MVC加载的请求映射文档。

编写Controller

@RestController("hello")
public class HelloController {
    @ApiOperation(value = "Hello World", authorizations = {@Authorization(value = "Authorization")})
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello(){
        
    }
}

访问swagger-ui界面

http://localhost:8080/swagger-ui.html/

参考资料

posted @ 2020-01-15 20:07  IT当时语_青山师  阅读(12)  评论(0)    收藏  举报  来源