java本服務(wù)如何調(diào)用本服務(wù)接口
java本服務(wù)調(diào)用本服務(wù)Feign接口
- 1.獲取所有@RequestMaping注解修飾的方法
- 2.構(gòu)建目標(biāo)url的RequestMappingInfo對(duì)象
- 3.獲取目標(biāo)url的Method對(duì)象
- 4.執(zhí)行
1.獲取所有@RequestMaping注解修飾的方法
Map<RequestMappingInfo, HandlerMethod> handlerMethods =
requestMappingHandlerMapping.getHandlerMethods();獲取結(jié)果類(lèi)型為Map<RequestMappingInfo, HandlerMethod> 其中RequestMappingInfo為請(qǐng)求映射信息(包含請(qǐng)求類(lèi)型,url)
public final class RequestMappingInfo implements RequestCondition<RequestMappingInfo> {
// 這個(gè)映射對(duì)象的名字
@Nullable
private final String name;
// 此RequestMappingInfo對(duì)象的URL模式
@Nullable
private final PathPatternsRequestCondition pathPatternsCondition;
// 此RequestMappingInfo的HTTP請(qǐng)求方法;
@Nullable
private final PatternsRequestCondition patternsCondition;
private final RequestMethodsRequestCondition methodsCondition;
// 此RequestMappingInfo的“參數(shù)”條件
private final ParamsRequestCondition paramsCondition;
// 此RequestMappingInfo的“headers”條件;
private final HeadersRequestCondition headersCondition;
private final ConsumesRequestCondition consumesCondition;
private final ProducesRequestCondition producesCondition;
private final RequestConditionHolder customConditionHolder;
private final int hashCode;
private final BuilderConfiguration options;
}HandlerMethod為該bean中對(duì)應(yīng)方法的信息(包括bean的名稱(chēng),入?yún)㈩?lèi)型,返回?cái)?shù)據(jù),方法名稱(chēng)等),源碼及注釋
public class HandlerMethod {
// bean的名稱(chēng),可通俗理解為類(lèi)名
private final Object bean;
@Nullable
private final BeanFactory beanFactory;
@Nullable
private final MessageSource messageSource;
// 方法所屬類(lèi)
private final Class<?> beanType;
// 對(duì)應(yīng)方法
private final Method method;
// 被橋接的方法,如果method是原生的,這個(gè)屬性的值就是method
private final Method bridgedMethod;
// 封裝方法參數(shù)的類(lèi)實(shí)例,一個(gè)MethodParameter就是一個(gè)參數(shù)
private final MethodParameter[] parameters;
@Nullable
private HttpStatus responseStatus;
@Nullable
private String responseStatusReason;
@Nullable
private HandlerMethod resolvedFromHandlerMethod;
@Nullable
private volatile List<Annotation[][]> interfaceParameterAnnotations;
private final String description;
}2.構(gòu)建目標(biāo)url的RequestMappingInfo對(duì)象
RequestMethod requestMethod = RequestMethod.GET ;
RequestMappingInfo requestMappingInfo =
RequestMappingInfo.paths("/export/getInfo").methods(requestMethod).build();3.獲取目標(biāo)url的Method對(duì)象
Method method = handlerMethods.get(requestMappingInfo).getMethod();
4.執(zhí)行
注意被執(zhí)行的一定是可以進(jìn)行實(shí)例化的類(lèi),不可以為接口或抽象類(lèi)
method.invoke(method.getDeclaringClass()); // 若存在參數(shù),則使用以下方案,其中param為入?yún)? method.invoke(method.getDeclaringClass(), param);
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot Web應(yīng)用開(kāi)發(fā) CORS 跨域請(qǐng)求支持
本篇文章主要介紹了Spring Boot Web應(yīng)用開(kāi)發(fā) CORS 跨域請(qǐng)求支持,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
org.springframework.dao.OptimisticLockingFailureException樂(lè)觀鎖
本文主要介紹了org.springframework.dao.OptimisticLockingFailureException樂(lè)觀鎖失敗的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-05-05
Java輕松提取PDF表格數(shù)據(jù)并轉(zhuǎn)換為CSV
在日常工作中,你是否曾為從 PDF 中手動(dòng)復(fù)制粘貼表格數(shù)據(jù)而抓狂,下面小編就和大家詳細(xì)介紹一下如何使用Java輕松高效地將提取的PDF 表格數(shù)據(jù)轉(zhuǎn)換為CSV吧2025-09-09
@Transactional解讀(作用、失效場(chǎng)景與解決方式)
這篇文章主要介紹了關(guān)于@Transactional作用、失效場(chǎng)景與解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
解決idea找不到setting.xml文件的問(wèn)題
這篇文章主要介紹了解決idea找不到setting.xml文件的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-02-02
springboot使用com.github.binarywang包實(shí)現(xiàn)微信網(wǎng)頁(yè)上的支付和退款
最近做項(xiàng)目需要實(shí)現(xiàn)在pc端需要實(shí)現(xiàn)微信的支付,本文主要介紹了springboot使用com.github.binarywang包實(shí)現(xiàn)微信網(wǎng)頁(yè)上的支付和退款,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05

