Remove most deprecated APIs that were due for removal in 4.0

Support for rest controller, controler, and servlet endpoints has
been kept for now.

Issue: 45600
This commit is contained in:
Andy Wilkinson
2025-06-10 20:11:08 +01:00
committed by Phillip Webb
parent bf385649ec
commit a78797a2ba
192 changed files with 94 additions and 10953 deletions

View File

@@ -47,7 +47,6 @@ import javax.tools.Diagnostic.Kind;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.InvalidConfigurationMetadataException;
import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation;
import org.springframework.boot.configurationprocessor.metadata.ItemHint;
import org.springframework.boot.configurationprocessor.metadata.ItemIgnore;
import org.springframework.boot.configurationprocessor.metadata.ItemMetadata;
@@ -346,19 +345,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
return; // Can't process that endpoint
}
String endpointKey = ItemMetadata.newItemMetadataPrefix("management.endpoint.", endpointId);
boolean enabledByDefaultAttribute = (boolean) elementValues.getOrDefault("enableByDefault", true);
String defaultAccess = (!enabledByDefaultAttribute) ? "none"
: (elementValues.getOrDefault("defaultAccess", "unrestricted").toString()).toLowerCase(Locale.ENGLISH);
boolean enabledByDefault = !"none".equals(defaultAccess) && enabledByDefaultAttribute;
String defaultAccess = elementValues.getOrDefault("defaultAccess", "unrestricted")
.toString()
.toLowerCase(Locale.ENGLISH);
String type = this.metadataEnv.getTypeUtils().getQualifiedName(element);
this.metadataCollector.addIfAbsent(ItemMetadata.newGroup(endpointKey, type, type, null));
ItemMetadata accessProperty = ItemMetadata.newProperty(endpointKey, "access", endpointAccessEnum(), type, null,
"Permitted level of access for the %s endpoint.".formatted(endpointId), defaultAccess, null);
this.metadataCollector.add(
ItemMetadata.newProperty(endpointKey, "enabled", Boolean.class.getName(), type, null,
"Whether to enable the %s endpoint.".formatted(endpointId), enabledByDefault,
new ItemDeprecation(null, accessProperty.getName(), "3.4.0")),
(existing) -> checkEnabledValueMatchesExisting(existing, enabledByDefault, type));
this.metadataCollector.add(accessProperty,
(existing) -> checkDefaultAccessValueMatchesExisting(existing, defaultAccess, type));
if (hasMainReadOperation(element)) {
@@ -367,22 +360,12 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
}
private void checkEnabledValueMatchesExisting(ItemMetadata existing, boolean enabledByDefault, String sourceType) {
boolean existingDefaultValue = (boolean) existing.getDefaultValue();
if (enabledByDefault != existingDefaultValue) {
throw new IllegalStateException(
"Existing property '%s' from type %s has a conflicting value. Existing value: %b, new value from type %s: %b"
.formatted(existing.getName(), existing.getSourceType(), existingDefaultValue, sourceType,
enabledByDefault));
}
}
private void checkDefaultAccessValueMatchesExisting(ItemMetadata existing, String defaultAccess,
String sourceType) {
String existingDefaultAccess = (String) existing.getDefaultValue();
if (!Objects.equals(defaultAccess, existingDefaultAccess)) {
throw new IllegalStateException(
"Existing property '%s' from type %s has a conflicting value. Existing value: %b, new value from type %s: %b"
"Existing property '%s' from type %s has a conflicting value. Existing value: %s, new value from type %s: %s"
.formatted(existing.getName(), existing.getSourceType(), existingDefaultAccess, sourceType,
defaultAccess));
}

View File

@@ -26,7 +26,6 @@ import org.springframework.boot.configurationprocessor.metadata.Metadata;
import org.springframework.boot.configurationsample.Access;
import org.springframework.boot.configurationsample.endpoint.CamelCaseEndpoint;
import org.springframework.boot.configurationsample.endpoint.CustomPropertiesEndpoint;
import org.springframework.boot.configurationsample.endpoint.DisabledEndpoint;
import org.springframework.boot.configurationsample.endpoint.EnabledEndpoint;
import org.springframework.boot.configurationsample.endpoint.NoAccessEndpoint;
import org.springframework.boot.configurationsample.endpoint.ReadOnlyAccessEndpoint;
@@ -53,18 +52,8 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
void simpleEndpoint() {
ConfigurationMetadata metadata = compile(SimpleEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.simple").fromSource(SimpleEndpoint.class));
assertThat(metadata).has(enabledFlag("simple", true));
assertThat(metadata).has(access("simple", Access.UNRESTRICTED));
assertThat(metadata).has(cacheTtl("simple"));
assertThat(metadata.getItems()).hasSize(4);
}
@Test
void disabledEndpoint() {
ConfigurationMetadata metadata = compile(DisabledEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.disabled").fromSource(DisabledEndpoint.class));
assertThat(metadata).has(enabledFlag("disabled", false));
assertThat(metadata).has(access("disabled", Access.NONE));
assertThat(metadata.getItems()).hasSize(3);
}
@@ -72,18 +61,16 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
void enabledEndpoint() {
ConfigurationMetadata metadata = compile(EnabledEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.enabled").fromSource(EnabledEndpoint.class));
assertThat(metadata).has(enabledFlag("enabled", true));
assertThat(metadata).has(access("enabled", Access.UNRESTRICTED));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
void noAccessEndpoint() {
ConfigurationMetadata metadata = compile(NoAccessEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.noaccess").fromSource(NoAccessEndpoint.class));
assertThat(metadata).has(enabledFlag("noaccess", false));
assertThat(metadata).has(access("noaccess", Access.NONE));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
@@ -91,9 +78,8 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(ReadOnlyAccessEndpoint.class);
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.readonlyaccess").fromSource(ReadOnlyAccessEndpoint.class));
assertThat(metadata).has(enabledFlag("readonlyaccess", true));
assertThat(metadata).has(access("readonlyaccess", Access.READ_ONLY));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
@@ -101,9 +87,8 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(UnrestrictedAccessEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.unrestrictedaccess")
.fromSource(UnrestrictedAccessEndpoint.class));
assertThat(metadata).has(enabledFlag("unrestrictedaccess", true));
assertThat(metadata).has(access("unrestrictedaccess", Access.UNRESTRICTED));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
@@ -114,20 +99,18 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
assertThat(metadata).has(Metadata.withProperty("management.endpoint.customprops.name")
.ofType(String.class)
.withDefaultValue("test"));
assertThat(metadata).has(enabledFlag("customprops", true));
assertThat(metadata).has(access("customprops", Access.UNRESTRICTED));
assertThat(metadata).has(cacheTtl("customprops"));
assertThat(metadata.getItems()).hasSize(5);
assertThat(metadata.getItems()).hasSize(4);
}
@Test
void specificEndpoint() {
ConfigurationMetadata metadata = compile(SpecificEndpoint.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific").fromSource(SpecificEndpoint.class));
assertThat(metadata).has(enabledFlag("specific", true));
assertThat(metadata).has(access("specific", Access.UNRESTRICTED));
assertThat(metadata).has(access("specific", Access.READ_ONLY));
assertThat(metadata).has(cacheTtl("specific"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
}
@Test
@@ -135,30 +118,27 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = compile(CamelCaseEndpoint.class);
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.pascal-case").fromSource(CamelCaseEndpoint.class));
assertThat(metadata).has(enabledFlag("PascalCase", "pascal-case", true));
assertThat(metadata).has(defaultAccess("PascalCase", "pascal-case", Access.UNRESTRICTED));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
void incrementalEndpointBuildChangeGeneralEnabledFlag() {
void incrementalEndpointBuildChangeDefaultAccess() {
TestProject project = new TestProject(IncrementalEndpoint.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata).has(access("incremental", Access.UNRESTRICTED));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"",
"id = \"incremental\", enableByDefault = false");
"id = \"incremental\", defaultAccess = org.springframework.boot.configurationsample.Access.NONE");
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", false));
assertThat(metadata).has(access("incremental", Access.NONE));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
}
@Test
@@ -167,45 +147,40 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
ConfigurationMetadata metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata).has(access("incremental", Access.UNRESTRICTED));
assertThat(metadata).has(cacheTtl("incremental"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
project.replaceText(IncrementalEndpoint.class, "@OptionalParameter String param", "String param");
metadata = project.compile();
assertThat(metadata)
.has(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
assertThat(metadata).has(enabledFlag("incremental", true));
assertThat(metadata).has(access("incremental", Access.UNRESTRICTED));
assertThat(metadata.getItems()).hasSize(3);
assertThat(metadata.getItems()).hasSize(2);
}
@Test
void incrementalEndpointBuildEnableSpecificEndpoint() {
void incrementalEndpointBuildChangeAccessOfSpecificEndpoint() {
TestProject project = new TestProject(SpecificEndpoint.class);
ConfigurationMetadata metadata = project.compile();
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific").fromSource(SpecificEndpoint.class));
assertThat(metadata).has(enabledFlag("specific", true));
assertThat(metadata).has(access("specific", Access.UNRESTRICTED));
assertThat(metadata).has(access("specific", Access.READ_ONLY));
assertThat(metadata).has(cacheTtl("specific"));
assertThat(metadata.getItems()).hasSize(4);
project.replaceText(SpecificEndpoint.class, "enableByDefault = true", "enableByDefault = false");
assertThat(metadata.getItems()).hasSize(3);
project.replaceText(SpecificEndpoint.class, "defaultAccess = Access.READ_ONLY", "defaultAccess = Access.NONE");
metadata = project.compile();
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific").fromSource(SpecificEndpoint.class));
assertThat(metadata).has(enabledFlag("specific", false));
assertThat(metadata).has(access("specific", Access.NONE));
assertThat(metadata).has(cacheTtl("specific"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
}
@Test
void shouldTolerateEndpointWithSameId() {
ConfigurationMetadata metadata = compile(SimpleEndpoint.class, SimpleEndpoint2.class);
assertThat(metadata).has(Metadata.withGroup("management.endpoint.simple").fromSource(SimpleEndpoint.class));
assertThat(metadata).has(enabledFlag("simple", "simple", true));
assertThat(metadata).has(defaultAccess("simple", "simple", Access.UNRESTRICTED));
assertThat(metadata).has(cacheTtl("simple"));
assertThat(metadata.getItems()).hasSize(4);
assertThat(metadata.getItems()).hasSize(3);
}
@Test
@@ -214,18 +189,7 @@ class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests {
.havingRootCause()
.isInstanceOf(IllegalStateException.class)
.withMessage(
"Existing property 'management.endpoint.simple.enabled' from type org.springframework.boot.configurationsample.endpoint.SimpleEndpoint has a conflicting value. Existing value: true, new value from type org.springframework.boot.configurationsample.endpoint.SimpleEndpoint3: false");
}
private Metadata.MetadataItemCondition enabledFlag(String endpointId, Boolean defaultValue) {
return enabledFlag(endpointId, endpointId, defaultValue);
}
private Metadata.MetadataItemCondition enabledFlag(String endpointId, String endpointSuffix, Boolean defaultValue) {
return Metadata.withEnabledFlag("management.endpoint." + endpointSuffix + ".enabled")
.withDefaultValue(defaultValue)
.withDescription(String.format("Whether to enable the %s endpoint.", endpointId))
.withDeprecation(null, "management.endpoint.%s.access".formatted(endpointSuffix), "3.4.0");
"Existing property 'management.endpoint.simple.access' from type org.springframework.boot.configurationsample.endpoint.SimpleEndpoint has a conflicting value. Existing value: unrestricted, new value from type org.springframework.boot.configurationsample.endpoint.SimpleEndpoint3: none");
}
private Metadata.MetadataItemCondition access(String endpointId, Access defaultValue) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
@@ -35,9 +35,6 @@ public @interface Endpoint {
String id() default "";
@Deprecated
boolean enableByDefault() default true;
Access defaultAccess() default Access.UNRESTRICTED;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
@@ -35,9 +35,6 @@ public @interface JmxEndpoint {
String id() default "";
@Deprecated
boolean enableByDefault() default true;
Access defaultAccess() default Access.UNRESTRICTED;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
@@ -35,9 +35,6 @@ public @interface RestControllerEndpoint {
String id() default "";
@Deprecated
boolean enableByDefault() default true;
Access defaultAccess() default Access.UNRESTRICTED;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
@@ -35,9 +35,6 @@ public @interface ServletEndpoint {
String id() default "";
@Deprecated
boolean enableByDefault() default true;
Access defaultAccess() default Access.UNRESTRICTED;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
@@ -35,9 +35,6 @@ public @interface WebEndpoint {
String id() default "";
@Deprecated
boolean enableByDefault() default true;
Access defaultAccess() default Access.UNRESTRICTED;
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2012-2025 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.boot.configurationsample.endpoint;
import org.springframework.boot.configurationsample.Endpoint;
/**
* An endpoint that is disabled unless configured explicitly.
*
* @author Stephane Nicoll
*/
@SuppressWarnings({ "deprecation", "removal" })
@Endpoint(id = "disabled", enableByDefault = false)
public class DisabledEndpoint {
}

View File

@@ -16,17 +16,17 @@
package org.springframework.boot.configurationsample.endpoint;
import org.springframework.boot.configurationsample.Access;
import org.springframework.boot.configurationsample.Endpoint;
import org.springframework.boot.configurationsample.ReadOperation;
/**
* A simple endpoint with no default override, with the same id as {@link SimpleEndpoint},
* but not enabled by default.
* but with no access by default.
*
* @author Moritz Halbritter
*/
@SuppressWarnings({ "deprecation", "removal" })
@Endpoint(id = "simple", enableByDefault = false)
@Endpoint(id = "simple", defaultAccess = Access.NONE)
public class SimpleEndpoint3 {
@ReadOperation

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.configurationsample.endpoint;
import org.springframework.boot.configurationsample.Access;
import org.springframework.boot.configurationsample.OptionalParameter;
import org.springframework.boot.configurationsample.ReadOperation;
import org.springframework.boot.configurationsample.WebEndpoint;
@@ -26,8 +27,7 @@ import org.springframework.boot.configurationsample.WebEndpoint;
*
* @author Stephane Nicoll
*/
@SuppressWarnings({ "deprecation", "removal" })
@WebEndpoint(id = "specific", enableByDefault = true)
@WebEndpoint(id = "specific", defaultAccess = Access.READ_ONLY)
public class SpecificEndpoint {
@ReadOperation