切面aspect处理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")
    	DataResult<AccountAlertConfDto> 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
  • 17
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值