我试图实现的是一个路由,例如:http://zuul-host:8080/v1/foo/hello
为我服务 foo-v1
, 资源 hello
我正在试用 正则表达式映射器 在 http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html 中描述的示例
我的问题是我看到一个名为 foo-v1
的服务被映射到 /v1/foo
在 PatternServiceRouteMapper
但后来我无法调用那条路线。在 /mappings
处也不可见.我是否必须在某处激活该路线?
设置
Foo 服务application.properties
server.port=9092
spring.application.name=foo-v1
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.healthcheck.enable=true
祖尔
我的配置类
Routings.java
.我为服务映射添加了一些 sysout 日志输出,我得到 foo-v1 -> v1/foo
在日志中。因此这个映射应该是事件的。@Configuration
public class Routings {
@Bean
public PatternServiceRouteMapper serviceRouteMapper() {
return new PatternServiceRouteMapper(
"(?<name>^.+)-(?<version>v.+$)",
"${version}/${name}") {
@Override
public String apply(final String serviceId) {
String route = super.apply(serviceId);
System.out.println(serviceId + " -> " +route);
return route;
}
};
}
}
我的
ZuulApplication.java
@SpringBootApplication
@EnableZuulProxy
@ComponentScan
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
@RefreshScope
@ConfigurationProperties("zuul")
public ZuulProperties zuulProperties() {
return new ZuulProperties();
}
}
最佳答案
好的,找到了解决方案。
删除 ignoredServices: '*'
从zuul配置。
如果您完成示例,就会发生这种情况。它们从显式配置的路由开始并忽略动态路由。它在文档中,但当时对我来说没有意义:-)
To skip having a service automatically added, set zuul.ignored-services to a list of service id patterns.
使用 regexmapper 时,我们开始使用自动添加的服务,这是我们使用
ignoredServices: '*'
禁用的功能。
关于spring-cloud - 如何在 Zuul 中使用基于 regexmapper 的路由? PatternServiceRouteMapper 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36566908/