When using spring-cloud-gateway-server-mvc ('springCloudVersion', "2024.0.0", 'org.springframework.boot' version '3.4.3', Java 21), the API Gateway failed to register with the Eureka Server with the following error:
2025-03-14T14:55:22.647+01:00 WARN 16425 --- [API Gateway] [foReplicator-%d] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: Unable to set redirect follow using reflection
2025-03-14T14:55:22.663+01:00 WARN 16425 --- [API Gateway] [foReplicator-%d] com.netflix.discovery.DiscoveryClient : DiscoveryClient_API GATEWAY/10.0.2.15:API Gateway - registration failed Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-2.0.4.jar:2.0.4]
The API Gateway can't register with the Eureka while using spring-cloud-gateway-server-mvc 'springCloudVersion', "2025.0.0-M2". The API Gateway registration with the Eureka works when using spring-cloud-gateway-server-mvc 'springCloudVersion', "2024.0.0-RC1" and 'org.springframework.boot' version '3.4.3' or 'springCloudVersion', "2023.0.5" and 'org.springframework.boot' version '3.3.9'
How to reproduce: 1. run eureka-server using ./gradlew bootRun, it should be available on http://localhost:8761/ 2. run API gateway using ./gradlew bootRun, and the registration error will be visible in the terminal (no instances registered with Eureka)
Example code provided: eureka-server.zip
Comment From: spencergibb
Also, removing gateway and just using spring-boot-starter-web
it registers fine, so this is odd.
Comment From: spencergibb
The underlying exception is
java.lang.IllegalStateException: Unable to set redirect follow using reflection
Comment From: spencergibb
This may be a boot issue that is only encountered when eureka client adds apache http client to the classpath.
Comment From: spencergibb
Setting spring.http.client.redirects=follow_when_possible
will work around the issue, but there may be unwanted side effects since the gateway server webmvc specifically sets this to dont_follow
Comment From: spencergibb
Turns out to be a bug with spring-cloud-netflix here https://github.com/spring-cloud/spring-cloud-netflix/blob/acf7485073e3d08f2e974084d9f5367c49a66b8e/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java#L125 shouldn't supply a lambda.