Для Например, в хранилище параметров AWS параметр «app.actuator.excludedEndpoints» пуст, поэтому конечная точка app/actuator/env должна вернуть правильный ответ (и это делает).
Но когда я тем временем меняю значение «app.actuator.excludedEndpoints» на env и использую «/refresh-actuator-config», я на самом деле в отладчике вы увидите, что он обновляет компонент «webEndpointProperties», который обновляется, а «excludedEndpoints» имеет новое значение, но в ответе на «/app/actuator/env» я все еще получаю предыдущий ответ (я должна получить ошибку!).
Код: Выделить всё
@Configuration
@RefreshScope
public class ManagementConfig {
@Value("${app.actuator.excludedEndpoints}")
private String excludedEndpoints;
@Autowired
private ConfigurableApplicationContext applicationContext;
@Bean
@Primary
@RefreshScope
public WebEndpointProperties webEndpointProperties() {
return createWebEndpointProperties();
}
private WebEndpointProperties createWebEndpointProperties() {
WebEndpointProperties properties = new WebEndpointProperties();
properties.setBasePath("/app/actuator");
Set excludedEndpointsSet = Set.of(excludedEndpoints.split(","));
properties.getExposure().setExclude(excludedEndpointsSet);
return properties;
}
@Bean
public WebFluxEndpointHandlerMapping webFluxEndpointHandlerMapping(
WebEndpointDiscoverer endpointDiscoverer) {
EndpointMapping endpointMapping = new EndpointMapping("/app/actuator");
Collection endpoints = endpointDiscoverer.getEndpoints();
EndpointMediaTypes mediaTypes = EndpointMediaTypes.DEFAULT;
EndpointLinksResolver linksResolver = new EndpointLinksResolver(endpoints);
return new WebFluxEndpointHandlerMapping(
endpointMapping,
endpoints,
mediaTypes,
null,
linksResolver,
true
);
}
public void refreshWebEndpointProperties() {
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext.getBeanFactory();
// Force environment refresh
ConfigurableEnvironment environment = applicationContext.getEnvironment();
environment.getPropertySources().iterator();
// Refresh web properties
beanFactory.destroySingleton("webEndpointProperties");
beanFactory.registerSingleton("webEndpointProperties", createWebEndpointProperties());
// Refresh handler mapping
beanFactory.destroySingleton("webFluxEndpointHandlerMapping");
applicationContext.getBean("webFluxEndpointHandlerMapping");
}
}
Код: Выделить всё
@RestController
public class ConfigRefreshController {
@Qualifier("configDataContextRefresher")
@Autowired
private ContextRefresher contextRefresher;
@Autowired
private ManagementConfig managementConfig;
@Autowired
private ConfigurableEnvironment environment;
@PostMapping("/refresh-actuator-config")
public String refreshConfig() {
contextRefresher.refresh();
managementConfig.refreshWebEndpointProperties();
return "Configuration refreshed";
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... t-runetime
Мобильная версия