启动应用程序:
@SpringBootApplication
@EnableZuulProxy
public class ZuulServer {
public static void main(String[] args) {
new SpringApplicationBuilder(ZuulServer.class).web(true).run(args);
}
}
我的YAML文件是这样的:
server:
port:8080
spring:
application:
name: zuul
eureka:
client:
enabled: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
zuul:
proxy:
route:
springapp: /springapp
我有一个名为springapp的微服务应用程序(在端口8081上),并有一些休息服务.以下是我的客户端UI应用:
TODO supply a title$.ajax({
url: 'http://localhost:8080/zuul/springapp/departments',
type: 'GET'
}).done(function (data) {
consoe.log(data);
document.write(data);
});
但我得到了一个
XMLHttpRequest cannot load http://localhost:8080/zuul/springapp/departments. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8383' is therefore not allowed access.
此UI HTML5应用程序位于http:// localhost:8383/SimpleAPp/index.html.CORS,CORS,CORS ......请帮忙.BTW http:// localhost:8080/zuul/springapp/departments在浏览器地址栏上返回一个json列表.spring.io博客在这里说没有必要使用过滤器,因为zuulproxy负责这个,但我不知道它为什么不适合我.