|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.util.Collection;
|
21 | 21 | import java.util.List;
|
22 | 22 |
|
| 23 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 24 | + |
23 | 25 | import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
|
24 | 26 | import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
25 | 27 | import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
26 | 28 | import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
|
27 | 29 | import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
28 | 30 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
| 31 | +import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType; |
| 32 | +import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider; |
29 | 33 | import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
30 | 34 | import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
31 | 35 | import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
|
42 | 46 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
43 | 47 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
44 | 48 | import org.springframework.context.annotation.Bean;
|
| 49 | +import org.springframework.context.annotation.Configuration; |
| 50 | +import org.springframework.core.Ordered; |
45 | 51 | import org.springframework.core.env.Environment;
|
| 52 | +import org.springframework.http.MediaType; |
| 53 | +import org.springframework.http.converter.HttpMessageConverter; |
| 54 | +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; |
46 | 55 | import org.springframework.util.StringUtils;
|
47 | 56 | import org.springframework.web.servlet.DispatcherServlet;
|
| 57 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
48 | 58 |
|
49 | 59 | /**
|
50 | 60 | * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Spring MVC
|
@@ -91,4 +101,35 @@ public ControllerEndpointHandlerMapping controllerEndpointHandlerMapping(
|
91 | 101 | corsProperties.toCorsConfiguration());
|
92 | 102 | }
|
93 | 103 |
|
| 104 | + @Configuration(proxyBeanMethods = false) |
| 105 | + public static class JsonWebMvcConfigurer implements WebMvcConfigurer, Ordered { |
| 106 | + |
| 107 | + private final ActuatorJsonMapperProvider actuatorJsonMapperProvider; |
| 108 | + |
| 109 | + public JsonWebMvcConfigurer(ActuatorJsonMapperProvider objectMapperFactory) { |
| 110 | + this.actuatorJsonMapperProvider = objectMapperFactory; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
| 115 | + converters.add(new ActuatorJsonHttpMessageConverter(this.actuatorJsonMapperProvider.getInstance())); |
| 116 | + } |
| 117 | + |
| 118 | + // WebMvcAutoConfiguration is ordered at 0 |
| 119 | + @Override |
| 120 | + public int getOrder() { |
| 121 | + return -1; |
| 122 | + } |
| 123 | + |
| 124 | + } |
| 125 | + |
| 126 | + static class ActuatorJsonHttpMessageConverter extends AbstractJackson2HttpMessageConverter { |
| 127 | + |
| 128 | + ActuatorJsonHttpMessageConverter(ObjectMapper objectMapper) { |
| 129 | + super(objectMapper, MediaType.parseMediaType(ActuatorMediaType.V3_JSON), |
| 130 | + MediaType.parseMediaType(ActuatorMediaType.V2_JSON)); |
| 131 | + } |
| 132 | + |
| 133 | + } |
| 134 | + |
94 | 135 | }
|
0 commit comments