现在项目使用得是springcloud,把每个模块得切成一个个服务,用来解耦,如何将他们联系起来呢,就是fegin远程调用,虽然操作比较简单,但是还是遇到了不少坑,所以在这里做下记录。
具体微服务操作常用介绍,以及fegin得简单运用可以见SpringCloud微服务框架搭建
这里主要讲fegin如何传参
1.marven配置
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
2.在启动类上加入注解
@EnableDiscoveryClient
@EnableFeignClients
3.重点fegin得inter接口
@FeignClient(value = "mgmtServer", name = "mgmtServer")
public interface ParkClientService {
@RequestMapping(value = "/srv/parkinghis/insert",method = RequestMethod.POST)
public SrvResult<?> insert(@RequestBody Map<String,Object> map);
}
重点是上面得@RequestBody
controller中如何进行调用呢
@ResponseBody
@RequestMapping(value = "/srv/parkinghis/insertyiku", method = RequestMethod.POST)
public SrvResult<?> insertyiku(@RequestBody Map<String,Object> map) {
Object reqInfoObject = map.get("requestinfo");
HttpRequestInfo reqInfo = JSON.parseObject(JSON.toJSONString(reqInfoObject), HttpRequestInfo.class);//将传过来
4.如果要传对象,只要把map换成对象即可,但是我这里一直报错。以下是报错以及我要进行传递得类
image.pngjava.lang.LinkageError: loader constraint violation: when resolving interface method
"com.macxen.mgmt.client.ParkClientService.insertyiku(Lcom/macxen/zhuang/client/HttpRequestInfo;)
Lcom/macxen/common/srv/out/SrvResult;" the class loader (instance of org/springframework/boot/devtools/restart/classloader/RestartClassLoader) of the current class,
com/macxen/zhuang/controller/AliPayMqttContr
oller, and the class loader (instance of sun/misc/Launcher$AppClassLoader)
for the method's defining class, com/macxen/mgmt/client/ParkClientService,
have different Class objects for the type com/macxen/zhuang/client/HttpRequestInfo
used in the signature
需要传递得类
image.png
5.思考:应该是引用jar包当中有重复得类导致,但是全局搜了下,没有重复得。为了安心,marven clean,marven deploy,然后在marven install下载下来,依然没有重复,可是还是报这错,无奈之下换方案之。
网友评论