|
30 | 30 | import org.springframework.boot.http.client.autoconfigure.HttpClientAutoConfiguration; |
31 | 31 | import org.springframework.boot.http.client.autoconfigure.HttpClientsProperties; |
32 | 32 | import org.springframework.boot.http.client.autoconfigure.imperative.ImperativeHttpClientsProperties; |
| 33 | +import org.springframework.boot.restclient.RestClientCustomizer; |
33 | 34 | import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration; |
34 | 35 | import org.springframework.boot.restclient.autoconfigure.RestTemplateAutoConfiguration; |
35 | 36 | import org.springframework.boot.test.context.FilteredClassLoader; |
|
48 | 49 | import org.springframework.cloud.gateway.server.mvc.predicate.PredicateAutoConfiguration; |
49 | 50 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient; |
50 | 51 | import org.springframework.context.ConfigurableApplicationContext; |
| 52 | +import org.springframework.context.annotation.Bean; |
| 53 | +import org.springframework.core.annotation.Order; |
51 | 54 |
|
52 | 55 | import static org.assertj.core.api.Assertions.assertThat; |
53 | 56 |
|
@@ -190,10 +193,45 @@ void loadBalancerFunctionHandlerNotAddedWhenNoLoadBalancerClientOnClasspath() { |
190 | 193 | .run(context -> assertThat(context).doesNotHaveBean("lbHandlerFunctionDefinition")); |
191 | 194 | } |
192 | 195 |
|
| 196 | + @Test |
| 197 | + void gatewayRestClientCustomizerHasOrderAnnotation() throws NoSuchMethodException { |
| 198 | + Order order = GatewayServerMvcAutoConfiguration.class |
| 199 | + .getMethod("gatewayRestClientCustomizer", org.springframework.beans.factory.ObjectProvider.class) |
| 200 | + .getAnnotation(Order.class); |
| 201 | + assertThat(order).isNotNull(); |
| 202 | + assertThat(order.value()).isEqualTo(0); |
| 203 | + } |
| 204 | + |
| 205 | + @Test |
| 206 | + void customRestClientCustomizerCanOverrideGatewayCustomizer() { |
| 207 | + new ApplicationContextRunner() |
| 208 | + .withConfiguration(AutoConfigurations.of(FilterAutoConfiguration.class, PredicateAutoConfiguration.class, |
| 209 | + HandlerFunctionAutoConfiguration.class, GatewayServerMvcAutoConfiguration.class, |
| 210 | + HttpClientAutoConfiguration.class, RestTemplateAutoConfiguration.class, |
| 211 | + RestClientAutoConfiguration.class, SslAutoConfiguration.class)) |
| 212 | + .withUserConfiguration(CustomRestClientCustomizerConfig.class) |
| 213 | + .run(context -> { |
| 214 | + assertThat(context).hasSingleBean(GatewayServerMvcAutoConfiguration.class); |
| 215 | + assertThat(context.getBeansOfType(RestClientCustomizer.class)).hasSize(2); |
| 216 | + }); |
| 217 | + } |
| 218 | + |
193 | 219 | @SpringBootConfiguration |
194 | 220 | @EnableAutoConfiguration |
195 | 221 | static class TestConfig { |
196 | 222 |
|
197 | 223 | } |
198 | 224 |
|
| 225 | + static class CustomRestClientCustomizerConfig { |
| 226 | + |
| 227 | + @Bean |
| 228 | + @Order(1) |
| 229 | + RestClientCustomizer customRestClientCustomizer() { |
| 230 | + return restClientBuilder -> { |
| 231 | + // Custom customizer that runs after gateway customizer |
| 232 | + }; |
| 233 | + } |
| 234 | + |
| 235 | + } |
| 236 | + |
199 | 237 | } |
0 commit comments