springclould feign client adds global parameters

With springclould feign as a client to invoke the service, general parameters can be written in method parameters feignclient's sometimes necessary to unify all feign requests to add some parameters, such as token for authentication, etc., you can do this:

Adding a configuration class, for example, the following code is sent to all requests are added feign a name msClientId, the value of the parameter header 8888

/**
 * Feign request interceptor
 * All requests issued by feign interceptors, note that feign a client makes a request, rather than the server
 */
@Configuration
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public  void Apply (requestTemplate requestTemplate) {
         // Here you can add global parameter request feign

    
        requestTemplate.header("msClientId", "8888");
    }
}

 

Guess you like

Origin www.cnblogs.com/cannel/p/11074465.html