跳至主要內容
Swagger

最好的API使用Swagger工具构建

1. springboot整合swagger2

导入swagger依赖(在maven项目pom.xml中添加以下依赖)
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
在主程序中添加@EnableSwagger2
@SpringBootApplication
@EnableSwagger2
public class MainApplication {
	public static void main(String[] args) {
		SpringApplication.run(MainApplication.class, args);
	}
}

在需要api的类上面添加注解
@RestController
@Api(tags = "UserinfoCtrl", description = "用户信息相关")  
public class testswaggercontroller {
	@RequestMapping("/testswagger")
	@ApiOperation(value = "获取用户信息", httpMethod = "GET", notes = "显示用户信息")  
	public Map<String, Object> fun() {
		Map<String , Object> result=new HashMap<String,Object>();
		result.put("test", "test");
		Demo demo=new Demo("junye", "1");
		result.put("Demo", demo);
		System.out.println("chenggong");
		return result;
	}
}
测试是否生成了api:浏览器访问:localhost:8080/swagger-ui.html#

HeChuangJun大约 3 分钟后端Swagger
nginx
  • Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。
  • 由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5万并发链接,并且cpu、内存等资源消耗却非常低,运行非常稳定。而且可以负载均衡

2. 应用场景

  • http服务器。Nginx是一个http服务可以独立提供http服务。可以做网页静态服务器。
  • 虚拟主机。可以实现在一台服务器虚拟出多个网站。例如个人网站使用的虚拟主机。
  • 反向代理,负载均衡。当网站的访问量达到一定程度后,单台服务器不能满足用户的请求时,需要用多台服务器集群可以使用nginx做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况。

HeChuangJun大约 6 分钟后端nginx