81°

支持多个 feign 路径

 

1、配置多个路径

@SpringBootApplication
@EnableSwagger2
@EnableFeignClients(basePackages = {"com.xx.city.priv.feign","com.xx.city.portal.feign"})
@EnableApolloConfig
public class PortalApplication {

 

2、自动获取


import feign.RequestInterceptor; import feign.RequestTemplate; import org.springframework.context.annotation.Configuration; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Configuration("portalFeignConfiguration") public class FeignConfiguration implements RequestInterceptor {

        @Override
        public void apply(RequestTemplate template) {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            String token = request.getHeader("Authorization");
            template.header("Authorization", token);
        }
    }

 

3、配置 jar

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

 

 

本文由【jxlgzwh】发布于开源中国,原文链接:https://my.oschina.net/zhongwenhao/blog/3073421

全部评论: 0

    我有话说: