我有一个问题,我使用jhipster生成了3种微服务:网关,uaa和赌博生产者。
当我使用docker-compose一起运行3个服务时,它运行良好,然后我停止了赌博生产者服务,并在localhost上为此服务运行./mvnw,当它们一起工作时不起作用。网关无法提供此服务

我尝试了一些情况:

  • 不要编辑上述3个服务的任何application.yaml,applicaton-dev.yml配置文件。
  • 在网关applicaton.yml上:
  •    routes:
        gamblingproducer:
          url: http://localhost:8081
    

    要么
     routes:
        gamblingproducer:
          path: services/gamblingproducer/**
          serviceId: gamblingproducer
    

    引发异常:Connect to localhost:8081 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
    gateway_1  | com.netflix.zuul.exception.ZuulException: Forwarding error
    gateway_1  |    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.handleException(SimpleHostRoutingFilter.java:261)
    gateway_1  |    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:241)
    gateway_1  |    at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117)
    gateway_1  |    at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193)
    gateway_1  |    at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157)
    gateway_1  |    at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:118)
    gateway_1  |    at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96)
    gateway_1  |    at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116)
    gateway_1  |    at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81)
    gateway_1  |    at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:166)
    gateway_1  |    at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:45)
    gateway_1  |    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)
    gateway_1  |    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    gateway_1  |    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    gateway_1  |    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    gateway_1  |    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    gateway_1  |    at javax.servlet.http.HttpServlet.service(HttpServlet.java:645)
    gateway_1  |    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    gateway_1  |    at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
    gateway_1  |    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:113)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:88)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
    gateway_1  |    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    gateway_1  |    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:180)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at microservices.gateway.web.filter.RefreshTokenFilter.doFilter(RefreshTokenFilter.java:62)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:97)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
    gateway_1  |    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    gateway_1  |    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
    gateway_1  |    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:114)
    gateway_1  |    at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:104)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    gateway_1  |    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    gateway_1  |    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    gateway_1  |    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    gateway_1  |    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    gateway_1  |    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    gateway_1  |    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    gateway_1  |    at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
    gateway_1  |    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
    gateway_1  |    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    gateway_1  |    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    gateway_1  |    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    gateway_1  |    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    gateway_1  |    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    gateway_1  |    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    gateway_1  |    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    gateway_1  |    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    gateway_1  |    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
    gateway_1  |    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    gateway_1  |    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
    gateway_1  |    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
    gateway_1  |    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
    gateway_1  |    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
    gateway_1  |    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    gateway_1  |    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    gateway_1  |    at java.lang.Thread.run(Thread.java:748)
    gateway_1  | Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8081 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
    gateway_1  |    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
    gateway_1  |    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
    gateway_1  |    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    gateway_1  |    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    gateway_1  |    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    gateway_1  |    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    gateway_1  |    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    gateway_1  |    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
    gateway_1  |    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:422)
    gateway_1  |    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:341)
    gateway_1  |    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:236)
    gateway_1  |    ... 116 common frames omitted
    gateway_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
    gateway_1  |    at java.net.PlainSocketImpl.socketConnect(Native Method)
    gateway_1  |    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    gateway_1  |    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    gateway_1  |    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    gateway_1  |    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    gateway_1  |    at java.net.Socket.connect(Socket.java:589)
    gateway_1  |    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    gateway_1  |    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    gateway_1  |    ... 126 common frames omitted
    gateway_1  |
    
    

    请帮我
    谢谢

    最佳答案

    始终将Localhost解析为容器本身的127.0.0.1。将localhost更改为运行eureka的主机ip或容器/服务名称,但不要使用localhost。当容器中的应用程序在分开的远程主机上运行时,请考虑一下它们。除非要循环回到同一个容器(几乎永远不会发生),否则切勿使用localhost。

    更新:

    就像我说的,基于注释部分,问题出在“本地主机”及其处理方式上。据我了解,情况看起来像这样:主机上的mvnw正在连接到docker中的eureka,并说:“嗨,我是mnvw,您可以在localhost:8081上与我联系”。但是,eureka在尝试进行验证时会调用localhost,而您的主机会获得eureka的localhost(即容器)。因此,解决您的问题的方法是让mnvw说出可以通过eureka容器(而不是localhost)找到的主机名(或ip)。在容器方面,使用localhost非常棘手,所以要注意!

    关于docker - 容器中的jhipster网关无法强制运行在localhost中的微服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59916104/

    10-16 11:00