我有一个AttachmentApi
服务类,它使用feign interface
位于JAR
我用作依赖项的文件中的两者client microservice
。
该controller
客户端微服务使用该AttachmentApi
服务从数据库获取数据。
当我访问该控制器的某个端点时,AttachmentApi 服务已成功自动连接,但 feign 接口没有,它给了我以下异常:
java.lang.NullPointerException: null
at ma.co.omnidata.framework.services.attachment.api.AttachmentApi.upload(AttachmentApi.java:26) ~[classes/:na]
at ma.co.omnidata.attachment.user.service.impl.AttachmentsUserService.uploadFile(AttachmentsUserService.java:21) ~[classes/:na]
at ma.co.omnidata.attachment.user.controllers.AttachmentUserController.uploadFile(AttachmentUserController.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144]
null 是由于没有自动装配的 feign 接口!
知道我在 springboot 类中使用了以下注释
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages= {"my.packages.including.the.feign.interface.package"})
任何建议将不胜感激谢谢!
更新 1
Feign 接口(位于 JAR 依赖项中)
@FeignClient(name="attachment-service", fallback=AttachmentHystrixFallback.class)
public interface AttachmentFeignClient {
@RequestMapping("attachment/{id}")
byte[] getAttachment(@PathVariable(name="id") String id);
@RequestMapping("attachments")
List<AttachmentDto> getAttachments(@RequestParam(name="attachableId") Long attachableId,
@RequestParam(name="className") String className, @RequestParam(name="appName") String appName);
@RequestMapping("upload")
void upload(MultipartFile file, @RequestParam(name="attachableId") Long attachableId,
@RequestParam(name="className") String className, @RequestParam(name="appName") String appName);
@RequestMapping("test")
String test();
}
AttachmentApi(也位于 JAR 依赖项中)
@Service
public class AttachmentApi implements IAttachmentApi {
@Autowired
AttachmentFeignClient client;
@Override
public byte[] getAttachment(String id) {
return client.getAttachment(id);
}
@Override
public void upload(IAttachable entity, MultipartFile file) {
client.upload(file, entity.getAttachableId(), entity.getClassName(), entity.getAppName());
}
@Override
public List<AttachmentDto> getAttachments(IAttachable entity) {
return client.getAttachments(entity.getAttachableId(), entity.getClassName(), entity.getAppName());
}
public String test() {
return client.test();
}
}
注意:我的客户端微服务无法自动装配位于 JAR 依赖项中的任何 bean(既不是 Feign 接口也不是 AttachmentApi 类)!