mirror of
https://github.com/spring-cloud/spring-cloud-netflix.git
synced 2026-09-17 15:49:00 +00:00
Use server customizer for Eureka Jackson mappings in mock server
Possible after Boot addressed https://github.com/spring-projects/spring-boot/issues/47798
This commit is contained in:
+12
-10
@@ -27,6 +27,7 @@ import com.netflix.discovery.shared.Application;
|
||||
import com.netflix.discovery.shared.Applications;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.http.converter.autoconfigure.ServerHttpMessageConvertersCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
@@ -111,15 +111,6 @@ public class EurekaServerMockApplication {
|
||||
.setNamespace("namespace1")
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Simulates Eureka Server own's serialization.
|
||||
* @return converter
|
||||
*/
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
|
||||
return EurekaHttpClientUtils.mappingJacksonHttpMessageConverter();
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PostMapping("/apps/{appName}")
|
||||
public void register(@PathVariable String appName, @RequestBody InstanceInfo instanceInfo) {
|
||||
@@ -189,6 +180,17 @@ public class EurekaServerMockApplication {
|
||||
return INFO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use this customizer to make sure we use the Jackson mappings for the Eureka server
|
||||
*/
|
||||
@Bean
|
||||
@Order
|
||||
ServerHttpMessageConvertersCustomizer customServerConvertersCustomizer() {
|
||||
return builder -> {
|
||||
builder.jsonMessageConverter(EurekaHttpClientUtils.mappingJacksonHttpMessageConverter());
|
||||
};
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
protected static class TestSecurityConfiguration {
|
||||
|
||||
+1
-8
@@ -34,14 +34,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
*/
|
||||
@SpringBootTest(classes = EurekaServerMockApplication.class,
|
||||
properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true",
|
||||
"eureka.client.fetch-registry=false", "eureka.client.register-with-eureka=false",
|
||||
// spring.http.converters.preferred-json-mapper=jackson2 is only necessary
|
||||
// to make the
|
||||
// mock Eureka Server used in this test to work
|
||||
// TODO we can likely remove this once this Boot issue is fixed post
|
||||
// 2025.1.0-RC1:
|
||||
// https://github.com/spring-projects/spring-boot/issues/47798
|
||||
"spring.http.converters.preferred-json-mapper=jackson2" },
|
||||
"eureka.client.fetch-registry=false", "eureka.client.register-with-eureka=false" },
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
class WebClientEurekaHttpClientTests extends AbstractEurekaHttpClientTests {
|
||||
|
||||
Reference in New Issue
Block a user