极致简洁的SpringBoot整合Swagger

微笑、不失礼 提交于 2020-01-25 07:25:36

极致简洁的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/

参考资料

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!