spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.53k stars 3.33k forks source link

spring.cloud.gateway.discovery.locator.enabled not working since 2.0.0.RC1 #344

Closed chinfeng closed 5 years ago

chinfeng commented 6 years ago

The spring.cloud.gateway.discovery.locator.enabled property not working since updated Finchley from M9 to RC2. It just keep response 404 all the time.

spencergibb commented 6 years ago

That's not enough information. What is your configuration and how to reproduce the error

chinfeng commented 6 years ago

Here is demo project.

eureka -> gateway -> hello

And then access http://localhost:8080/hello/

It just work fine in Finchley.M9 version. You can change it in build.gradle or root project.

gateway-demo.tar.gz

chinfeng commented 6 years ago

I think i found the problem.

ServiceInstance::getServiceId is returning upper case name since Finchley.RC1. Route pattern is created in upper case ( /HELLO/** in my demo project for example ). The org.springframework.web.util.pattern.LiteralPathElement instance using by PathRoutePredicateFactory is case sensitive ( prop caseSensitive is true) .

So it always return 404 because "/HELLO/**"not matching with "/hello/" while caseSensitive==true

sgornostal commented 6 years ago

Not working for me with 'Finchley.RELEASE' and Spring boot '2.0.3.RELEASE' My configuration:

build.gradle

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-actuator',
            'org.springframework.boot:spring-boot-starter-webflux',
            'org.springframework.cloud:spring-cloud-starter-consul-discovery',
            'org.springframework.cloud:spring-cloud-starter-gateway',
            'org.springframework.boot:spring-boot-starter-aop',
            'org.springframework.retry:spring-retry'
}

bootstrap.properties

spring.application.name=edge-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.consul.discovery.health-check-path=/actuator/health
spring.cloud.consul.host=${CONSUL_HOST:localhost}

application.properties

server.port=8080
management.endpoints.web.exposure.include=*

Application.class

@EnableDiscoveryClient
@SpringBootApplication
public class Application {

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

GET http://localhost:8080/actuator/gateway/routes returns empty list.

spencergibb commented 6 years ago

@chinfeng for eureka it has always returned upper case. There is a property to force the route to lowercase, I'll find it later.

chinfeng commented 6 years ago

Thanks @spencergibb .

But why this problem wasn't there unitl Finchley.RC1 ?

longshine commented 6 years ago

I found this property work:

spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true

See DiscoveryLocatorProperties.lowerCaseServiceId

chinfeng commented 6 years ago

@longshine Thanks! It works!

But this property doesn't included in documents even Finchley.RELEASE.

conanca commented 5 years ago

@sgornostal refer to https://stackoverflow.com/questions/48383556/spring-cloud-gateway-routes-from-consul?rq=1

byatham commented 8 months ago

Please check your dependency like below

org.springframework.cloud spring-cloud-starter-gateway

it should not contain like below

org.springframework.cloud spring-cloud-starter-gateway-mvc

Please remove -mvc from in dependency.