Search code examples
spring-cloudnetflix-zuul

spring cloud zuul can not works with a simple example code


I'm newbie to Spring Cloud. Following the example of Start Guide. I'm stuck at Zuul example.

With a request to zuul, my client app not receive any request from zuul and get 405(Method not allowed) to my browser.
But test without zuul, the client app can response success.

Simple code as this:
Zuul Server:

@EnableZuulProxy
@SpringBootApplication
public class MyZuulApp {

    public static void main(String[] args) {
        SpringApplication.run(MyZuulApp.class, args);
    }

    @Bean
    public SimpleFilter simpleFilter() {
        return new SimpleFilter();
    }

}

Configuration:

##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

Client App:

@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);
    }
}

Configuration:

spring.application.name=book_app

server.port=8090

logging.level.org.springframework.web=DEBUG

Full code has organized at Github.
See my-zuul and book-app for that situation.
Thanks


Solution

  • I downloaded your code and run locally and it worked as expected.

    Your Zuul application.properties

      zuul.routes.book_app.url=http://localhost:8090
      server.port=8083
    

    Since your book application name is book_app.Zuul will proxy request to /book_app.So you have to send requests like this: http://localhost:8083/book_app/checked-out/.