Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ';全球';未被所有外国客户接收到的外国拦截器_Java_Spring Boot_Spring Cloud Feign - Fatal编程技术网

Java ';全球';未被所有外国客户接收到的外国拦截器

Java ';全球';未被所有外国客户接收到的外国拦截器,java,spring-boot,spring-cloud-feign,Java,Spring Boot,Spring Cloud Feign,我们在应用程序中使用Open-Feign,它运行在Spring Boot 2.0.6和Spring Cloud Finchley.SR2上 我们需要所有外部客户端在每个调用的头中添加来自安全上下文的令牌,因此我们创建了一个配置,为所有客户端生成一个全局拦截器: @Configuration @Import({FeignClientsConfiguration.class}) public class FeignConfig { @Value("${a.spring.config}")

我们在应用程序中使用Open-Feign,它运行在Spring Boot 2.0.6和Spring Cloud Finchley.SR2上

我们需要所有外部客户端在每个调用的头中添加来自安全上下文的令牌,因此我们创建了一个配置,为所有客户端生成一个全局拦截器:

@Configuration
@Import({FeignClientsConfiguration.class})
public class FeignConfig {

   @Value("${a.spring.config}")
   private int minTokenLifespan;

   @Autowired
   private OAuthContext oAuthContext;

   @Autowired
   private AuthManager authManager;

   @Bean
   public RequestInterceptor myCustomInterceptor() {
       return new CustomInterceptor(oAuthContext, authManager, minTokenLifespan);
   }
}
拦截器适用于除一个外的所有外国客户机。在调试器中,我们可以看到,在类
FeignConfig
中创建Bean之前,已经创建了这个特殊的外部客户机(及其SynchronousMessageHandler)。
CustomIntercepter
仅在第一个外国客户机之后创建,所有其他客户机都是在第一个外国客户机之后创建的,知道存在拦截器并将应用它

我们如何调试这个问题?过去有没有人遇到过不同的问题


我不能发布生产代码,但我很乐意回答任何问题,并尝试发布模糊代码。

这表明在创建第一个客户端时创建拦截器存在问题

尝试在
RequestInterceptor.class
上的
org.springframework.beans.factory.support.DefaultListableBeanFactory#getBeansOfType
中放置一个条件断点。您可能会看到,存在一个循环依赖项,它要求在实例化
FeignConfig
CustomInterceptor
类之前创建第一个客户机

考虑以下示例:

@配置
@启用伪装客户端(
客户={
MyFirstClient.class,//将不注册CustomInterceptor
MySecondClient.class//将注册CustomInterceptor
})
公共类假配置{
@自动连线
私人BeanDependentOnMyFirstClient BeanDependentOnMyFirstClient;
@豆子
公共请求侦听器myCustomInterceptor(){
返回新的CustomInterceptor();
}
}
这将导致以下循环依赖关系:


由于客户机和拦截器之间的依赖关系很弱,如果无法满足依赖关系,它将无声地失败。

不幸的是,我再也无法访问代码库了。您描述的场景非常匹配,但是,谢谢!