Browse Source

Moved beans to GatewayServerMvcAutoConfiguration

mvc-server
spencergibb 2 years ago committed by sgibb
parent
commit
6dbab9c9c9
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 39
      spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/GatewayServerMvcAutoConfiguration.java
  2. 1
      spring-cloud-gateway-server-mvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  3. 16
      spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

39
spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/GatewayServerMvcAutoConfiguration.java

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.gateway.server.mvc;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
@AutoConfiguration(after = RestTemplateAutoConfiguration.class)
public class GatewayServerMvcAutoConfiguration {
@Bean
public ClientHttpRequestFactory gatewayClientHttpRequestFactory(RestTemplateBuilder builder) {
return builder.buildRequestFactory();
}
@Bean
public ClientHttpRequestFactoryProxyExchange clientHttpRequestFactoryProxyExchange(
ClientHttpRequestFactory requestFactory) {
return new ClientHttpRequestFactoryProxyExchange(requestFactory);
}
}

1
spring-cloud-gateway-server-mvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@ -0,0 +1 @@ @@ -0,0 +1 @@
org.springframework.cloud.gateway.server.mvc.GatewayServerMvcAutoConfiguration

16
spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

@ -28,7 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest; @@ -28,7 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.gateway.server.mvc.test.DefaultTestRestClient;
import org.springframework.cloud.gateway.server.mvc.test.HttpBinCompatibleController;
import org.springframework.cloud.gateway.server.mvc.test.LocalHostUriBuilderFactory;
@ -38,7 +37,6 @@ import org.springframework.context.annotation.Bean; @@ -38,7 +37,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;
@ -109,19 +107,7 @@ public class ServerMvcIntegrationTests { @@ -109,19 +107,7 @@ public class ServerMvcIntegrationTests {
@EnableAutoConfiguration
protected static class TestConfiguration {
// TODO: move to auto config
@Bean
public ClientHttpRequestFactory gatewayClientHttpRequestFactory(RestTemplateBuilder builder) {
return builder.buildRequestFactory();
}
@Bean
public ClientHttpRequestFactoryProxyExchange clientHttpRequestFactoryProxyExchange(
ClientHttpRequestFactory requestFactory) {
return new ClientHttpRequestFactoryProxyExchange(requestFactory);
}
// TODO: move to auto config
// TODO: move to test auto config
@Bean
public DefaultTestRestClient testRestClient(TestRestTemplate testRestTemplate, Environment env) {
return new DefaultTestRestClient(testRestTemplate, new LocalHostUriBuilderFactory(env), result -> {

Loading…
Cancel
Save