Spring Boot小技巧总结

Feign客户端直接指定IP调用服务

1
2
3
4
@FeignClient(value = "appblog-provider-channel-core", url="192.168.1.10:8888")
public interface ChannelPayApi extends IChannelPayApi {

}

获取请求Header

1
2
3
public Result<Response> query(@PathVariable("id") String id, @RequestHeader("token") String token) {

}

RequestContext请求上下文设置与获取

1
2
3
4
5
public class GatewayPreFilter extends ZuulFilter {

@Override
public Object run() throws ZuulException {
RequestContext.getCurrentContext().set(String key, Object value);
1
2
3
4
5
6
public class GatewayPostFilter extends ZuulFilter {

@Override
public Object run() throws ZuulException {
RequestContext requestContext = RequestContext.getCurrentContext();
Object value = (String) requestContext.get(String key);

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :