Java service calls the Feign interface of this service
- 1. Get all @RequestMaping annotation modification methods
- 2. Build the RequestMappingInfo object of the target url
- 3. Get the Method object of the target url
- 4. Execute
1. Get all @RequestMaping annotation modification methods
Map<RequestMappingInfo, HandlerMethod> handlerMethods = ();
Get the result type Map<RequestMappingInfo, HandlerMethod> where RequestMappingInfo is the request mapping information (including the request type, url)
public final class RequestMappingInfo implements RequestCondition<RequestMappingInfo> { // The name of this map object @Nullable private final String name; // URL pattern of this RequestMappingInfo object @Nullable private final PathPatternsRequestCondition pathPatternsCondition; // This RequestMappingInfo HTTP request method; @Nullable private final PatternsRequestCondition patternsCondition; private final RequestMethodsRequestCondition methodsCondition; // "Parameter" condition of this RequestMappingInfo private final ParamsRequestCondition paramsCondition; // The "headers" condition of this RequestMappingInfo; 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 is the information of the corresponding method in the bean (including the name of the bean, parameter type, return data, method name, etc.), source code and comments
public class HandlerMethod { // The name of bean can be commonly understood as class name private final Object bean; @Nullable private final BeanFactory beanFactory; @Nullable private final MessageSource messageSource; // The method belongs to the class private final Class<?> beanType; // Corresponding method private final Method method; // The method being bridged, if the method is native, the value of this property is method private final Method bridgedMethod; // Encapsulate a class instance of method parameters, a MethodParameter is a parameter 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. Build the RequestMappingInfo object of the target url
RequestMethod requestMethod = ; RequestMappingInfo requestMappingInfo = ("/export/getInfo").methods(requestMethod).build();
3. Get the Method object of the target url
Method method = (requestMappingInfo).getMethod();
4. Execute
Note that the executed class must be instantiated, not interface or abstract class.
(()); // If there are parameters, use the following scheme, where param is the entry parameter((), param);
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.