1

我使用 @EnableSidecar 创建了一个 spring-boot 应用程序,我看到为已注册的 eureka 客户端“offers”和“customers”创建了一条路由(Mapped URL path [/customers/**] onto ...),并且路由显示在http://localhost:9000/routes端点上:

{
    "_links":{
        "self":{
            "href":"http://localhost:8090/routes"
        }
    },
    "/customers/**":"customers",
    "/zuul-proxy/**":"zuul-proxy",
    "/offers/**":"offers"
}

在浏览器中的 zuul-proxy 上访问http://localhost:9000/customers时,我得到一个 404 的想法。

我的应用程序.yml

spring:
  application:
    name: zuul-proxy

server:
  port: 9000    

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

ZuulProxyApplication.java:

@EnableSidecar
@SpringBootApplication
public class ZuulProxyApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulProxyApplication.class, args);
    }
}

日志输出:

2015-09-11 23:33:09.236  INFO 42750 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
2015-09-11 23:33:09.237  INFO 42750 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application zuul-proxy with eureka with status UP
2015-09-11 23:33:09.238  INFO 42750 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [current=UP, previous=STARTING]
2015-09-11 23:33:09.241  INFO 42750 --- [           main] o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/customers/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-09-11 23:33:09.242  INFO 42750 --- [           main] o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/offers/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-09-11 23:33:09.245  INFO 42750 --- [           main] ch.local.zuul.ZuulProxyApplication       : Started ZuulProxyApplication in 8.637 seconds (JVM running for 9.26)
2015-09-11 23:33:09.245  INFO 42750 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_ZUUL-PROXY/192.168.0.108: registering service...
2015-09-11 23:33:09.294  INFO 42750 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_ZUUL-PROXY/192.168.0.108 - registration status: 204
2015-09-11 23:33:14.545  INFO 42750 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2015-09-11 23:33:14.545  INFO 42750 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2015-09-11 23:33:14.572  INFO 42750 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 27 ms
2015-09-11 23:33:14.616  INFO 42750 --- [nio-8090-exec-1] o.s.c.n.zuul.filters.ProxyRouteLocator   : Finding route for path: /customers
2015-09-11 23:33:14.626  INFO 42750 --- [nio-8090-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7442808: startup date [Fri Sep 11 23:33:14 CEST 2015]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3a60c416
2015-09-11 23:33:14.646  INFO 42750 --- [nio-8090-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-09-11 23:33:14.759  INFO 42750 --- [nio-8090-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: customers.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-09-11 23:33:14.802  INFO 42750 --- [nio-8090-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-customers
2015-09-11 23:33:14.829  INFO 42750 --- [nio-8090-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client:customers instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=customers,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2015-09-11 23:33:14.855  INFO 42750 --- [nio-8090-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: customers.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-09-11 23:33:14.858  INFO 42750 --- [nio-8090-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client customers initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=customers,current list of Servers=[192.168.0.108:customers - 8083, 192.168.0.108:customers - 8081],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:2;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:192.168.0.108:customers - 8081;    Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 01:00:00 CET 1970;  First connection made: Thu Jan 01 01:00:00 CET 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
, [Server:192.168.0.108:customers - 8083;   Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 01:00:00 CET 1970;  First connection made: Thu Jan 01 01:00:00 CET 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@55d7aafe
2015-09-11 23:33:14.941  INFO 42750 --- [nio-8090-exec-1] com.netflix.http4.ConnectionPoolCleaner  : Initializing ConnectionPoolCleaner for NFHttpClient:customers
2015-09-11 23:33:15.838  INFO 42750 --- [ool-10-thread-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: customers.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-09-11 23:33:19.287  INFO 42750 --- [nio-8090-exec-2] o.s.c.n.zuul.filters.ProxyRouteLocator   : Finding route for path: /customers
2015-09-11 23:33:35.780  INFO 42750 --- [pool-3-thread-1] o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/zuul-proxy/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]

我看到在 eureka 中注册的客户和优惠实例。我还可以通过 zuul-proxy 应用程序中的 RestTemplate 访问它们,例如:

@RestController
public class TestController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/test")
    public Customer test() {
        return restTemplate.getForObject("http://customers/customers/1", Customer.class);
    }
} 

当我调用http://localhost:9000/test时,这是有效的

注册路由http://localhost:9000/customershttp://localhost:9000/offers得到 404 可能是什么问题?

4

0 回答 0