如何发布自己做的网站,ai智能写作平台,米业做网站的好处,网络媒体发稿切面处理fegin调用转本地调用 问题:原fegin调用转本地调用详细描述方案代码实现总结问题:原fegin调用转本地调用
项目原来是微服务项目服务与服务之间是通过fegin进行交互的,但是现在微服务项目要重构为单体项目,原fegin调用的方法要给为本地调用
详细描述
zyy-aiot │ … 切面处理fegin调用转本地调用 问题:原fegin调用转本地调用详细描述方案代码实现总结 问题:原fegin调用转本地调用
项目原来是微服务项目服务与服务之间是通过fegin进行交互的,但是现在微服务项目要重构为单体项目,原fegin调用的方法要给为本地调用
详细描述
zyy-aiot │ ├── zyy-aiot-modules │ └── zyy-account │ └└── zyy-account-client │ └└── zyy-account-client-api │ └└── zyy-account-manage │ └└── zyy-account-manage-api │└── zyy-customer │ └└── zyy-customer-client │ └└── zyy-customer-client-api │ └└── zyy-customer-manage │ └└── zyy-customer-manage-api │ ├── zyy-aiot-service │ └└── ZyyAiotServiceApplication.java
这是我的项目结构ZyyAiotServiceApplication.java是springboot启动类,(zyy-account-client-api,zyy-account-manage-api,zyy-customer-client-api,zyy-customer-manage-api)内部定义了Fegin给其他服务调用,下面是fegin的一个示例:
@FeignClient("zyy-aiot-service")
public interface AccountAlertConfMnFeign {@PostMapping("/manage/accountAlertConf/selectPhoneListByCustomerIdAndType")@ApiOperation(value = "根据客户id获取提醒人手机号列表", httpMethod = "POST")DataResultAccountAlertConfDto selectPhoneListByCustomerIdAndType(@RequestBody AccountAlertConfDto dto);}}之前的zyy-account-client和zyy-customer-client就是通过feginClient进行交互的,现在不想分开部署这两个模块了,目前是将上面的模块打到一个jar包中运行。
方案
第一步.在spring启动时获取项目所有springMVC的controller对象。以及其中url和函数,放到公共容器中保存。 第二部.切面所以fegin接口,在调用fegin接口时通过url去匹配上一步获取到的对应controller对象和相关url接口函数发起调用并且返回结果
代码实现
获取springMVC对象
package com.zyy.aiot.service.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandle