Spring boot 佯装-使用单个配置,但指定应注入的bean
我使用FeinClient向外部服务发出http请求,但我需要创建两个不同的外国客户端,因为它们根据请求使用不同的头:Spring boot 佯装-使用单个配置,但指定应注入的bean,spring-boot,spring-cloud-feign,feign,Spring Boot,Spring Cloud Feign,Feign,我使用FeinClient向外部服务发出http请求,但我需要创建两个不同的外国客户端,因为它们根据请求使用不同的头: 在身份验证请求中,它使用标题“Authorization Basic…” 在其他请求上,它使用标题“授权承载者…” 为了实现这一目标,我创建了两个具有不同配置的外部客户端: class FBAuthFeignConfiguration () { @Bean fun basicAuthRequestInterceptor() = BasicAuthReque
- 在身份验证请求中,它使用标题“Authorization Basic…”
- 在其他请求上,它使用标题“授权承载者…”
class FBAuthFeignConfiguration () {
@Bean
fun basicAuthRequestInterceptor() = BasicAuthRequestInterceptor("admin", "admin")
}
class WhatsAppFeignConfiguration {
@Bean
fun requestInterceptor(): RequestInterceptor {
return RequestInterceptor {
it.header("Authorization", "Bearer ...")
}
}
}
我的客户:
@FeignClient(name = "FBAuthRepository", url = "\${fb.url}", configuration = [FBAuthFeignConfiguration::class])
interface FBAuthRepository {
@PostMapping(value = ["/login"], produces = ["application/json"])
fun login(): Login
}
@FeignClient(name = "FBRepository", url = "\${fb.url}", configuration = [FBFeignConfiguration::class])
interface FBRepository {
@PostMapping(
value = ["/v1/any"])
fun anyUrl(@RequestBody payload: String): Response
}
有没有办法指定何时使用标题或其他?我不喜欢在同一个域中有多个客户机的想法,而且我也不确定这是否是一种使用佯攻的模式