应用程序.java
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableZuulProxy
public class ZuulServer {
public static void main(String[] args) {
SpringApplication.run(ZuulServer.class, args);
}
}
应用程序.yml
eureka:
client:
enabled: true
serviceUrl:
defaultZone: http://localhost:8761/v2/
zuul:
proxy:
route:
service1: /myservice1
service2: /myservice2
示例调用:
http://localhost:8080/proxy/myservice1/users
http://localhost:8080/proxy/myservice2/auctionlots/today
预装饰过滤器在路由期间工作,出现以下错误(使用 1.0.0.M2):
Caused by: java.lang.NoSuchMethodError: com.netflix.hystrix.HystrixExecutableBase$ObservableCommand.toBlocking()Lrx/observables/BlockingObservable;
at com.netflix.hystrix.HystrixExecutableBase.queue(HystrixExecutableBase.java:342)
at com.netflix.hystrix.HystrixObservableCommand.queue(HystrixObservableCommand.java:50)
at com.netflix.hystrix.HystrixExecutableBase.execute(HystrixExecutableBase.java:296)
at com.netflix.hystrix.HystrixObservableCommand.execute(HystrixObservableCommand.java:50)
at com.netflix.hystrix.HystrixCommand.execute(HystrixCommand.java:485)
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:162)
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:86)
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112)
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:197)
... 41 common frames omitted