Indefinite path request mapping spring mvc

The company projects the overall structure of migration from the original spring + zk + thrift transferred to the spring-cloud, build a spring-cloud family bucket, the new micro-services module interfaces written in the background, access to the original domain name, encountered a manual forward The problem.

 

The original management background, called admin-api, is a spring mvc project, providing http interface with existing back-end thrift various projects linked to the front, play a role in the conversion http request. Spring-cloud newly established projects, providing a unified access through zuul domain name, but different and original domain name, there is access control and security issues.

 

The most primitive schemes provided in the admin-api Controller, correspond to the same spring-cloud engineering interface problem can be solved, but the work is very tedious repetition, because the interface in the form of spring-cloud exposed to a relatively stable (get request or post json request), it was decided encapsulation (duplicate logic, it is where the code should automatically).

Option One:

Add controller, determine the starting path and set the path variable, and then call zuul forwarded according to the path variable and serviceName path, but not sure how many class path variable, there is constantly updated follow-up work, give up

 

Option II:

Add controller, path determination, while adding Interceptor, intercepts the request specified rule, and stores the acquired path variable attributes, the generation of the controller from forward to a specified, variable forward path is acquired.

Results: In the building of spring-boot successfully, smoothly forward, but in the original project encountered problems DispatcherServlet intercepted Reviewing spring mvc found that all requests will go through the servlet, after confirming there is a path mapping, it HandlerInterceptorAdapter put before the next class will be, so the actual project, I interceptors in a real utility, the request has been returned, spent the rest of the changes are more in abeyance.

 

third solution:

When a program is about to retry, stumbled upon the support spring mvc another variable path, the request format is as follows:

    @RequestMapping(value = "/myGateway/{serviceName}/**")
    public String moduleStrings(@PathVariable String serviceName, HttpServletRequest request) throws Exception {

In the above case, the controller intercepts begin myGateway, and containing at least Request-URI serviceName, and then I request acquired in the path variable, resolution request carrying parameters and body parameters, resolution request mode (GET POST) to complete a lightweight mini meet the current scene gateway services,

 

Published 20 original articles · won praise 0 · views 10000 +

Guess you like

Origin blog.csdn.net/u011248560/article/details/100146628