简体   繁体   中英

Zuul Gateway No redirecting to client server

I have configured a zuul server with a single client application. But when I hit the URL with Zuul Gateway, it does not redirect to the client service and gives the error

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

My Zuul Server config ( application.yml)

server:
  port: 8080

zuul:
  routes:
    client-service:
      path: /asd/**
      #      url: http://localhost:8081/home
      url: http://localhost:8081/login

My Client Service Config:

server:
  port: 8081


spring:
  application:
    name: client-service

Controller in Client Service

@RestController
@RequestMapping("/login")
public class LoginController {

    @GetMapping
    public String findAll() {
        return "simple login get method method";
    }
}

Result when hit the client service endpoint ( client service directly )

Endpoint : http://localhost:8081/login
Result : simple login get method method

Result when hit the endpoint ( via gateway )

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

I guess you missed enabling the zuul proxy on gateway server

@EnableZuulProxy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM