Tiven Wang
Tiven Wang July 10, 2017
425 favorite favorites
bookmark bookmark
share share

Thailand Buffalo Racing Festival,中文稱為『泰國水牛節』,是泰國歷史非常悠久的活動慶典。每年約於十月份(農曆的九月十四),在泰國的春武里府(Chonburi Province) 來舉辦。 泰國水牛節,據說在距今一百年多前,就出現在泰國中南半島。在農業時代,水牛是泰國農民耕作和運輸的主要工具。為了感激水牛的辛勤工作,農民為水牛們舉辦了一個活動,讓水牛可以充分休息一天。活動演變至今,慢慢發展成水牛競賽。活動內容包含了水牛賽跑比賽,看看誰能在水牛的背上待最久,另外還有選美比賽,優勝者可以得到水牛小姐封號(Miss Buffalo)。

OpenAPI

Spring REST Docs

我們使用 Springfox 在 Spring MVC 框架上實現 Swagger API文檔說明。

Setup

Dependency

添加 Springfox 的 Maven 依賴:

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

Swagger Configuration

@Configuration
@EnableSwagger2
public class SwaggerConfig {

  @Bean
  public Docket api() {
      return new Docket(DocumentationType.SWAGGER_2)  
        .select()                                  
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())                          
        .build();
  }
}

訪問鏈接可查看 json格式的 API 信息:/v2/api-docs

Swagger UI

下載 Swagger UI 項目代碼,拷貝 dist 目錄下的文件到 server 靜態頁面目錄如 src/main/webapp/swagger-ui/

git clone https://github.com/swagger-api/swagger-ui.git

修改 index.html 文件中的 API url:

// Build a system
const ui = SwaggerUIBundle({
  url: "/v2/api-docs",
  ...
});

訪問 <server>/swagger-ui/index.html 可看到 API 的文檔界面。

API Information

Annotations

References

Similar Posts

  • Spring Boot - Apache Camel This article shows how to work with a simple Apache Camel application using Spring Boot.
  • Microservices - API Gateway Implement an API gateway that is the single entry point for all clients. The API gateway handles requests in one of two ways. Some requests are simply proxied/routed to the appropriate service. It handles other requests by fanning out to multiple services.
  • Microservices - Circuit Breaker 访问远程服务时, 比依赖超时时间更好一些的方式是一种叫断路器(Circuit Breaker)的模式. Circuit Breaker 就像一位交通警察, 在前方道路畅通的情况下, 他会放行; 当前方道路由于各种原因拥堵时, 他会告诉你前方道路不通请回; 如果他是个更智能的交警的话, 还会告诉你前方道路部分拥堵, 只允许部分车辆通过, 比如实行单双号.
  • Microservices - Architecture Microservice architecture (MSA) is an approach to building software systems that decomposes business domain models into smaller, consistent, bounded-contexts implemented by services. These services are isolated and autonomous yet communicate to provide some piece of business functionality. Microservices are typically implemented and operated by small teams with enough autonomy that each team and service can change its internal implementation details (including replacing it outright!) with minimal impact across the rest of the system.
  • Microservices - Load Balancing 在微服务架构中每个服务都可能有多个运行实例, 那么服务消费者在调用服务时怎么定位应该把请求发送给哪个实例呐? 这就是负载均衡 Load Balancing 要做的事情。Load Balancing 可以在服务端也可以是在消费端。
  • Microservices - Service Discovery Clients of a service use either Client-side discovery or Server-side discovery to determine the location of a service instance to which to send requests. Why use Service Discovery?

Comments

comments powered by Disqus
Back to Top