我有一个AttachmentApi
服务类,它使用位于feign interface
文件中的JAR
,我在client microservice
中使用它作为依赖项。
该客户端微服务的controller
使用AttachmentApi
服务从db获取数据
当我访问该控制器的某个端点时,AttachmentApi服务是
成功自动装配,但假装界面不是,它给了我以下例外:
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是由于没有自动装配的假装接口!
知道我在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类)!
答案 0 :(得分:0)
试试这个
@EnableFeignClients(clients = {AttachmentFeignClient.class})