SpringCloud feign調用 請求頭擴展


feign調用有時候會需要在請求頭中傳入特殊屬性,feign提供了這個擴展接口

public interface RequestInterceptor {

  /**
   * Called for every request. Add data using methods on the supplied {@link RequestTemplate}.
   */
  void apply(RequestTemplate template);
}

demo如下

public void apply(RequestTemplate input) {
   input.header("X-Auth";, currentToken);
}

接口說明:

Zero or more RequestInterceptors may be configured for purposes such as adding headers to
all requests. No guarantees are give with regards to the order that interceptors are applied.

RequestInterceptors 用於在request上添加header,有多個是不能保證順序。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM