Zuul网关无法转发请求至客户端服务的问题求助
Zuul网关请求转发404问题排查
我配置了一个Zuul网关服务器及单个客户端应用,但通过Zuul网关访问URL时,请求并未转发至客户端服务,而是返回404错误。以下是相关日志、配置信息及测试结果:
错误日志
2022-08-21 19:25:39.120+0200 [http-nio-8080-exec-1] DEBUG o.s.w.servlet.DispatcherServlet - GET "/asd", parameters={} 2022-08-21 19:25:39.120+0200 [http-nio-8080-exec-1] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"] 2022-08-21 19:25:39.121+0200 [http-nio-8080-exec-1] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found 2022-08-21 19:25:39.121+0200 [http-nio-8080-exec-1] DEBUG o.s.w.servlet.DispatcherServlet - Completed 404 NOT_FOUND 2022-08-21 19:25:39.122+0200 [http-nio-8080-exec-1] DEBUG o.s.w.servlet.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={} 2022-08-21 19:25:39.123+0200 [http-nio-8080-exec-1] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse) 2022-08-21 19:25:39.123+0200 [http-nio-8080-exec-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String 2022-08-21 19:25:39.127+0200 [http-nio-8080-exec-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.template.provider.cache' in PropertySource 'configurationProperties' with value of type String 2022-08-21 19:25:39.131+0200 [http-nio-8080-exec-1] DEBUG o.s.w.s.v.ContentNegotiatingViewResolver - Selected 'text/html' given [text/html, text/html;q=0.8] 2022-08-21 19:25:39.131+0200 [http-nio-8080-exec-1] DEBUG o.s.w.servlet.DispatcherServlet - Exiting from "ERROR" dispatch, status 404
Zuul服务器配置(application.yml)
server: port: 8080 zuul: routes: client-service: path: /asd/** # url: http://localhost:8081/home url: http://localhost:8081/login
客户端服务配置
server: port: 8081 spring: application: name: client-service
客户端服务控制器
@RestController @RequestMapping("/login") public class LoginController { @GetMapping public String findAll() { return "simple login get method method"; } }
测试结果
- 直接访问客户端服务端点:
Endpoint : http://localhost:8081/login Result : simple login get method method
- 通过网关访问端点:
Endpoint : http://localhost:8080/asd Result : Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Aug 21 19:30:45 CEST 2022 There was an unexpected error (type=Not Found, status=404). No message available
内容的提问来源于stack exchange,提问作者user1379280
相关产品推荐
相关产品推荐

