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.51k stars 3.31k forks source link

Gateway 2020.0.0-M4 seems to ignore spring-cloud-starter-config, works in 2020.0.0-M3. #1998

Closed magnus-larsson closed 3 years ago

magnus-larsson commented 3 years ago

Describe the bug Starting with Spring Cloud 2020.0.0-M4 it seems like the spring-cloud-gateway ignores the dependency to spring-cloud-starter-config, resulting in that the gateway doesn't try to lookup its configuration from the config server at startup. This works fine using Spring Cloud 2020.0.0-M3.

Sample Create, build and run a gateway based on Spring Cloud 2020.0.0-M4 using Spring Initializr CLI:

spring init \
--boot-version=2.4.0.M3 \
--build=gradle \
--java-version=1.8 \
--packaging=jar \
--name=gateway \
--package-name=se.magnus.springcloud.gateway \
--groupId=se.magnus.springcloud.gateway \
--dependencies=actuator,security,cloud-gateway,cloud-config-client \
--version=1.0.0-SNAPSHOT \
ml-gateway

cd ml-gateway
./gradlew build

java -jar build/libs/ml-gateway-1.0.0-SNAPSHOT.jar

The log output from the startup will look like (lacking attempts to fetch its config from the config server):

2020-10-24 10:47:07.204  INFO 34133 --- [           main] s.m.s.gateway.GatewayApplication         : Starting GatewayApplication using Java 1.8.0_222 on Magnus-MBP32.local with PID 34133 (/Users/magnus/Documents/projects/bok-2nd-edition/git/bok-1st-edition/Chapter14/spring-cloud/ml-gateway/build/libs/ml-gateway-1.0.0-SNAPSHOT.jar started by magnus in /Users/magnus/Documents/projects/bok-2nd-edition/git/bok-1st-edition/Chapter14/spring-cloud/ml-gateway)
2020-10-24 10:47:07.207  INFO 34133 --- [           main] s.m.s.gateway.GatewayApplication         : No active profile set, falling back to default profiles: default

Changing Spring Cloud version to 2020.0.0-M3 in build.gradle + rebuild and run will result in the expected log output during the startup:

2020-10-24 11:05:59.702  INFO 61391 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-10-24 11:05:59.806  INFO 61391 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-10-24 11:05:59.806  WARN 61391 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/application/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2020-10-24 11:05:59.808  INFO 61391 --- [           main] s.m.s.gateway.GatewayApplication         : No active profile set, falling back to default profiles: default

Note: Since I don't have any Spring Config server up and running, the Connection refused error is expected.

magnus-larsson commented 3 years ago

Found the answer in https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available, simply adding a dependency to org.springframework.cloud:spring-cloud-starter-bootstrap solved the issue.