我已经使用几个 Spring Cloud 服务(配置、服务注册表和 Zuul)设置了一个本地环境。代理使用默认映射正确地公开服务:
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/api-proxy/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/service-discovery/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/config-service/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/circuitbreaker-collector/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
2015-11-23 14:06:30.184 INFO 11532 --- [ main] o.s.c.n.zuul.web.ZuulHandlerMapping : Mapped URL path [/circuitbreaker-dashboard/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]
我看到的问题是,当我转到http://localhost/service-discovery/时,我看到了 Eureka 仪表板,但没有加载任何相关的静态资源。浏览器显示如下错误:
http://localhost/eureka/css/wro.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/eureka/js/wro.js Failed to load resource: the server responded with a status of 404 (Not Found)
service-discovery:223 Uncaught ReferenceError: $ is not defined
http://localhost/eureka/css/wro.css Failed to load resource: the server responded with a status of 404 (Not Found)
有没有办法解决这个问题?据我所知,Eureka 仪表板在加载资源时没有使用相对路径,而是假设应用程序已部署到根 servlet 上下文。
更新 我意识到我错过了代表问题。我评论了这个帖子,但我想我会把它带到主帖。问题是 Zuul 代表客户端发出后端请求。当 Zuul 发出该请求时,HTML 响应包含相对于为 Eureka 配置的上下文路径的 URL。通常,代理服务将通过重写响应中找到的任何 URL 来管理这一点,以具有关于代理如何公开它的正确基本上下文。Zuul 是否存在类似的东西?
更改主题以更好地描述问题。