mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #28475 from davidh44
* pr/28475: Polish "Create EndpointWebExtension only if necessary" Create EndpointWebExtension only if necessary Closes gh-28475
This commit is contained in:
commit
62d87f95d3
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.cache;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure;
|
||||
import org.springframework.boot.actuate.cache.CachesEndpoint;
|
||||
import org.springframework.boot.actuate.cache.CachesEndpointWebExtension;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
@ -53,6 +54,7 @@ public class CachesEndpointAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(CachesEndpoint.class)
|
||||
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB)
|
||||
public CachesEndpointWebExtension cachesEndpointWebExtension(CachesEndpoint cachesEndpoint) {
|
||||
return new CachesEndpointWebExtension(cachesEndpoint);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.context.properties;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure;
|
||||
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint;
|
||||
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpointWebExtension;
|
||||
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
|
||||
@ -62,6 +63,7 @@ public class ConfigurationPropertiesReportEndpointAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(ConfigurationPropertiesReportEndpoint.class)
|
||||
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB)
|
||||
public ConfigurationPropertiesReportEndpointWebExtension configurationPropertiesReportEndpointWebExtension(
|
||||
ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint) {
|
||||
return new ConfigurationPropertiesReportEndpointWebExtension(configurationPropertiesReportEndpoint);
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.env;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure;
|
||||
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpoint;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpointWebExtension;
|
||||
@ -60,6 +61,7 @@ public class EnvironmentEndpointAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(EnvironmentEndpoint.class)
|
||||
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB)
|
||||
public EnvironmentEndpointWebExtension environmentEndpointWebExtension(EnvironmentEndpoint environmentEndpoint) {
|
||||
return new EnvironmentEndpointWebExtension(environmentEndpoint);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.quartz;
|
||||
import org.quartz.Scheduler;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure;
|
||||
import org.springframework.boot.actuate.quartz.QuartzEndpoint;
|
||||
import org.springframework.boot.actuate.quartz.QuartzEndpointWebExtension;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
@ -53,6 +54,7 @@ public class QuartzEndpointAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnBean(QuartzEndpoint.class)
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB)
|
||||
public QuartzEndpointWebExtension quartzEndpointWebExtension(QuartzEndpoint endpoint) {
|
||||
return new QuartzEndpointWebExtension(endpoint);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.cache;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.cache.CachesEndpoint;
|
||||
import org.springframework.boot.actuate.cache.CachesEndpointWebExtension;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cache.CacheManager;
|
||||
@ -64,4 +65,13 @@ class CachesEndpointAutoConfigurationTests {
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(CachesEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
|
||||
this.contextRunner.withBean(CacheManager.class, () -> mock(CacheManager.class))
|
||||
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
|
||||
"management.endpoints.jmx.exposure.include=caches")
|
||||
.run((context) -> assertThat(context).hasSingleBean(CachesEndpoint.class)
|
||||
.doesNotHaveBean(CachesEndpointWebExtension.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint;
|
||||
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties;
|
||||
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpointWebExtension;
|
||||
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ -102,6 +103,15 @@ class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
|
||||
"management.endpoints.jmx.exposure.include=configprops")
|
||||
.run((context) -> assertThat(context).hasSingleBean(ConfigurationPropertiesReportEndpoint.class)
|
||||
.doesNotHaveBean(ConfigurationPropertiesReportEndpointWebExtension.class));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties
|
||||
static class Config {
|
||||
|
@ -25,6 +25,7 @@ import org.springframework.boot.actuate.env.EnvironmentEndpoint;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor;
|
||||
import org.springframework.boot.actuate.env.EnvironmentEndpointWebExtension;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
@ -93,6 +94,15 @@ class EnvironmentEndpointAutoConfigurationTests {
|
||||
.run(validateSystemProperties("******", "******"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
|
||||
"management.endpoints.jmx.exposure.include=env")
|
||||
.run((context) -> assertThat(context).hasSingleBean(EnvironmentEndpoint.class)
|
||||
.doesNotHaveBean(EnvironmentEndpointWebExtension.class));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> validateSystemProperties(String dbPassword, String apiKey) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(EnvironmentEndpoint.class);
|
||||
|
@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.quartz.Scheduler;
|
||||
|
||||
import org.springframework.boot.actuate.quartz.QuartzEndpoint;
|
||||
import org.springframework.boot.actuate.quartz.QuartzEndpointWebExtension;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -71,6 +72,15 @@ class QuartzEndpointAutoConfigurationTests {
|
||||
.run((context) -> assertThat(context).hasSingleBean(QuartzEndpoint.class).hasBean("customEndpoint"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
|
||||
this.contextRunner.withBean(Scheduler.class, () -> mock(Scheduler.class))
|
||||
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
|
||||
"management.endpoints.jmx.exposure.include=quartz")
|
||||
.run((context) -> assertThat(context).hasSingleBean(QuartzEndpoint.class)
|
||||
.doesNotHaveBean(QuartzEndpointWebExtension.class));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomEndpointConfiguration {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user