Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot 如何为特定客户机设置自定义的伪请求拦截器?_Spring Boot_Kotlin_Feign - Fatal编程技术网

Spring boot 如何为特定客户机设置自定义的伪请求拦截器?

Spring boot 如何为特定客户机设置自定义的伪请求拦截器?,spring-boot,kotlin,feign,Spring Boot,Kotlin,Feign,我需要添加自定义授权头到一些新的外国客户。所以我写了一个RequestInterceptor,它工作了,但关键是我不希望这个定制的RequestInterceptor影响我的老客户机。我尝试使用template.url()方法进行筛选,但它没有提供请求的整个url,它只包含客户端方法url(而不是在客户端类上方宣布的url和路径)。 我的问题是,我如何瞄准拦截器 这是我的配置: @Configuration open class FeignCustomConfiguration { p

我需要添加自定义授权头到一些新的外国客户。所以我写了一个RequestInterceptor,它工作了,但关键是我不希望这个定制的RequestInterceptor影响我的老客户机。我尝试使用template.url()方法进行筛选,但它没有提供请求的整个url,它只包含客户端方法url(而不是在客户端类上方宣布的url和路径)。 我的问题是,我如何瞄准拦截器

这是我的配置:

@Configuration
open class FeignCustomConfiguration {

    private fun generateToken(): String { ... }

    @Bean
    open fun requestInterceptor(): RequestInterceptor {
        return RequestInterceptor {
            it.header("Authorization", generateToken())
        }
    }
}
我找到了解决办法。 对于每个假客户端,都有一个
配置
选项,它接受一个类数组。在kotlin中将类分配给配置的语法如下:

@FeignClient(
        name = "feign-client",
        path = "/path",
        url = "https://example.com",
        configuration = [FeignCustomConfiguration::class]
)
interface FeignCustomClient {
     ...
}
通过此分配,每个假客户端都有自己的配置,RequestInterceptor不处理其他客户端