[英]How to i configure Feign Client in java spring
I want to insert data to another database with Feign, and i have error我想用 Feign 将数据插入另一个数据库,但我有错误
This Configuration此配置
@Configuration
public class ServiceFeignClientConfig {
public ErrorDecoder errorDecoderBeeShop(Decoder decoder) {
return (String methodKey, Response response) -> {
try {
ResponseShop respEnvelope = (ResponseShop) decoder.decode(response, ResponseShop.class);
MarshallingUtils.printJson(respEnvelope);
ErrCode errCode = ErrCode.toError(respEnvelope.getMeta().getCode());
String errMessage = respEnvelope.getMeta().getMessage();
return new Exception(errCode, errMessage);
} catch (Exception e) {
e.printStackTrace();
return new Exception(ErrCode.ERR_UNKNOWN, ErrCode.ERR_UNKNOWN.getMessage());
}
};
}
This Service Feign Client这个服务假装客户端
@FeignClient(name = "beeshop-service", url = "http://localhost:9008/", configuration = {ServiceFeignClientConfig.class})
public interface BeeShopServiceClient {
@PutMapping("v1/input-user")
void inputUser(String merchantName, String phoneNumber, String email, Role.ERole roleMerchant);
}
And i want to call this endpoint to my Controller我想将此端点称为我的 Controller
beeShopService.updateOrderStatus(merchantName, phoneNumber, email, roleMerchant);
And when i run this application i have error当我运行此应用程序时出现错误
Unsatisfied dependency expressed through constructor parameter 0;通过构造函数参数 0 表示的不满足的依赖关系; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.beepay.service.internal.BeeShopServiceClient': Unexpected exception during bean creation;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“com.beepay.service.internal.BeeShopServiceClient”的 bean 时出错:创建 bean 期间出现意外异常; nested exception is java.lang.NoClassDefFoundError: feign/Capability嵌套异常是 java.lang.NoClassDefFoundError: feign/Capability
How I resolve this?我如何解决这个问题? sorry my bad englist对不起我的坏英语
You do not need the @Configuration in the configuration class for feign:您不需要配置 class 中的 @Configuration 用于 feign:
Configuration does not need to be annotated with @Configuration.配置不需要使用@Configuration 注解。 However, if it is, then take care to exclude it from any @ComponentScan that would otherwise include this configuration as it will become the default source for feign.Decoder, feign.Encoder, feign.Contract, etc., when specified.但是,如果是,请注意将其从任何可能包含此配置的 @ComponentScan 中排除,因为在指定时它将成为 feign.Decoder、feign.Encoder、feign.Contract 等的默认源。 This can be avoided by putting it in a separate, non-overlapping package from any @ComponentScan or @SpringBootApplication, or it can be explicitly excluded in @ComponentScan.这可以通过将其从任何@ComponentScan 或@SpringBootApplication 放在一个单独的、不重叠的package 中来避免,或者可以在@ComponentScan 中明确排除它。
ref: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html参考: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html
Also make sure to enable feign via: @EnableFeignClients in you main config class还要确保通过主配置 class 中的 @EnableFeignClients 启用 feign
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.