Springcloud Fegin Get will be automatically converted to Post

problem description

when actually accessing API, it is the way of POST;

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

@RequestMapping(value = "/permission/current",method = RequestMethod.GET )
@Headers({"Content-Type: application/json","Authorization:{token}"})
Map<String,Object> getPermission(@Param("token") String token);

what result do you expect? What is the error message actually seen?

how can I modify it to support Headers Authorization token, or Springcloud Fegin does not support it here?

Jul.25,2021

you can add an Interceptor, put token to header, then you do not have to send token as a param for all the function.

public class FeignBasicAuthRequestInterceptor  implements RequestInterceptor {
    public FeignBasicAuthRequestInterceptor() {
    }
    @Override
    public void apply(RequestTemplate template) {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        String token = (String)request.getSession().getAttribute("Authorization");
        template.header("Authorization", token);
    }
}
@Configuration
public class FeignConfiguration {

    /**
     * Feigntoken,token
     * @return
     */
    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new FeignBasicAuthRequestInterceptor();
    }

    /**
     * feigin 
     *
     * @return
     */
    @Bean
    public Logger.Level feignLoggerLevel() {
        return feign.Logger.Level.FULL;
    }
}

take a look at this article https://blog.csdn.net/qq_3632.

Menu