spring cloud zuul 无法使用简单的示例代码
spring cloud zuul can not works with a simple example code
我是 Spring Cloud 的新手。以 Start Guide 为例。我被困在 Zuul 的例子中。
在向 zuul 发出请求时,我的客户端应用程序未收到来自 zuul 的任何请求,并向我的浏览器发送 405(方法不允许)。
但是在没有zuul的情况下测试,客户端app可以响应成功。
简单代码如下:
Zuul 服务器:
@EnableZuulProxy
@SpringBootApplication
public class MyZuulApp {
public static void main(String[] args) {
SpringApplication.run(MyZuulApp.class, args);
}
@Bean
public SimpleFilter simpleFilter() {
return new SimpleFilter();
}
}
配置:
##Zuul routes. Here for /student path, we are routing to localhost:8090 with extra path after that.
zuul.routes.book_app.url=http://localhost:8090
#zuul.routes.book_app=/book_app/**
##Ribbon is auto integrated with Zuul and for this exercise we are not using that.
ribbon.eureka.enabled=false
##Will start the gateway server @8080
server.port=8083
logging.level.org.springframework.web=DEBUG
客户端应用程序:
@RestController
@SpringBootApplication
public class BookApp {
@RequestMapping(value = "/available")
public String available() {
System.out.println("get abailable - ");
return "Spring in Action";
}
@RequestMapping(value = "/checked-out")
public String checkedOut() {
return "Spring Boot in Action";
}
public static void main(String[] args) {
SpringApplication.run(BookApp.class, args);
}
}
配置:
spring.application.name=book_app
server.port=8090
logging.level.org.springframework.web=DEBUG
完整代码已组织在 Github。
有关这种情况,请参阅 my-zuul 和 book-app。
谢谢
我在本地下载了您的代码和 运行,它按预期工作。
你的祖尔application.properties
zuul.routes.book_app.url=http://localhost:8090
server.port=8083
因为你的图书应用程序名称是 book_app.Zuul 将代理请求到 /book_app。所以你必须像这样发送请求:http://localhost:8083/book_app/checked-out/.
我是 Spring Cloud 的新手。以 Start Guide 为例。我被困在 Zuul 的例子中。
在向 zuul 发出请求时,我的客户端应用程序未收到来自 zuul 的任何请求,并向我的浏览器发送 405(方法不允许)。
但是在没有zuul的情况下测试,客户端app可以响应成功。
简单代码如下:
Zuul 服务器:
@EnableZuulProxy
@SpringBootApplication
public class MyZuulApp {
public static void main(String[] args) {
SpringApplication.run(MyZuulApp.class, args);
}
@Bean
public SimpleFilter simpleFilter() {
return new SimpleFilter();
}
}
配置:
##Zuul routes. Here for /student path, we are routing to localhost:8090 with extra path after that.
zuul.routes.book_app.url=http://localhost:8090
#zuul.routes.book_app=/book_app/**
##Ribbon is auto integrated with Zuul and for this exercise we are not using that.
ribbon.eureka.enabled=false
##Will start the gateway server @8080
server.port=8083
logging.level.org.springframework.web=DEBUG
客户端应用程序:
@RestController
@SpringBootApplication
public class BookApp {
@RequestMapping(value = "/available")
public String available() {
System.out.println("get abailable - ");
return "Spring in Action";
}
@RequestMapping(value = "/checked-out")
public String checkedOut() {
return "Spring Boot in Action";
}
public static void main(String[] args) {
SpringApplication.run(BookApp.class, args);
}
}
配置:
spring.application.name=book_app
server.port=8090
logging.level.org.springframework.web=DEBUG
完整代码已组织在 Github。
有关这种情况,请参阅 my-zuul 和 book-app。
谢谢
我在本地下载了您的代码和 运行,它按预期工作。
你的祖尔application.properties
zuul.routes.book_app.url=http://localhost:8090
server.port=8083
因为你的图书应用程序名称是 book_app.Zuul 将代理请求到 /book_app。所以你必须像这样发送请求:http://localhost:8083/book_app/checked-out/.