Skip to content

Commit

Permalink
Deprecate framework-specific @*Endpoint annotations
Browse files Browse the repository at this point in the history
Prior to this commit, applications could declare Actuator Endpoints
using web framework-specific annotations, such as `@ServletEndpoint`,
@ControllerEndpoint and @RestControllerEndpoint.

Such annotations are closely tied to the programming model of specific
web technologies, such as Servlet or Spring MVC. Unlike other
`@Endpoint` support, they are not portable and will not work
transparently over blocking/reactive and transports.

Because of the strong adherence of this support with the underlying
infrastructure, it makes it impossible to evolve the implementation of
Actuator support without breaking this use case. The reference
documentation has been advocating for using `@Endpoint` and
`@*Operation` for custom endpoints for a long time now.

This commit deprecates this specific support in favor of the recommended
approach.

Closes spring-projectsgh-31768
  • Loading branch information
bclozel committed Apr 15, 2024
1 parent 34c6075 commit 647a5ec
Show file tree
Hide file tree
Showing 44 changed files with 91 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -111,6 +111,7 @@ public CloudFoundryInfoEndpointWebExtension cloudFoundryInfoEndpointWebExtension
}

@Bean
@SuppressWarnings("removal")
public CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServletHandlerMapping(
ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes,
RestTemplateBuilder restTemplateBuilder, ServletEndpointsSupplier servletEndpointsSupplier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -47,6 +47,7 @@
public class ServletEndpointManagementContextConfiguration {

@Bean
@SuppressWarnings("removal")
public IncludeExcludeEndpointFilter<ExposableServletEndpoint> servletExposeExcludePropertyEndpointFilter(
WebEndpointProperties properties) {
WebEndpointProperties.Exposure exposure = properties.getExposure();
Expand All @@ -56,6 +57,7 @@ public IncludeExcludeEndpointFilter<ExposableServletEndpoint> servletExposeExclu

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(DispatcherServlet.class)
@SuppressWarnings("removal")
public static class WebMvcServletEndpointManagementContextConfiguration {

@Bean
Expand All @@ -70,6 +72,7 @@ public ServletEndpointRegistrar servletEndpointRegistrar(WebEndpointProperties p
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ResourceConfig.class)
@ConditionalOnMissingClass("org.springframework.web.servlet.DispatcherServlet")
@SuppressWarnings("removal")
public static class JerseyServletEndpointManagementContextConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -96,6 +96,7 @@ public WebEndpointDiscoverer webEndpointDiscoverer(ParameterValueMapper paramete

@Bean
@ConditionalOnMissingBean(ControllerEndpointsSupplier.class)
@SuppressWarnings("removal")
public ControllerEndpointDiscoverer controllerEndpointDiscoverer(ObjectProvider<PathMapper> endpointPathMappers,
ObjectProvider<Collection<EndpointFilter<ExposableControllerEndpoint>>> filters) {
return new ControllerEndpointDiscoverer(this.applicationContext, endpointPathMappers.orderedStream().toList(),
Expand Down Expand Up @@ -124,6 +125,7 @@ public IncludeExcludeEndpointFilter<ExposableControllerEndpoint> controllerExpos

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET)
@SuppressWarnings("removal")
static class WebEndpointServletConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -84,6 +84,7 @@ class JerseyWebEndpointManagementContextConfiguration {
private static final EndpointId HEALTH_ENDPOINT_ID = EndpointId.of("health");

@Bean
@SuppressWarnings("removal")
JerseyWebEndpointsResourcesRegistrar jerseyWebEndpointsResourcesRegistrar(Environment environment,
WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes, WebEndpointProperties webEndpointProperties) {
Expand Down Expand Up @@ -124,6 +125,7 @@ private boolean shouldRegisterLinksMapping(WebEndpointProperties properties, Env
/**
* Register endpoints with the {@link ResourceConfig} for the management context.
*/
@SuppressWarnings("removal")
static class JerseyWebEndpointsResourcesRegistrar implements ManagementContextResourceConfigCustomizer {

private final WebEndpointsSupplier webEndpointsSupplier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -82,6 +82,7 @@ public class WebMvcEndpointManagementContextConfiguration {

@Bean
@ConditionalOnMissingBean
@SuppressWarnings("removal")
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author Phillip Webb
* @author Madhura Bhave
*/
@SuppressWarnings("removal")
class ServletEndpointManagementContextConfigurationTests {

private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void webApplicationSupportCustomPathMatcher() {
}

@Test
@SuppressWarnings("removal")
void webApplicationConfiguresEndpointDiscoverer() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(ControllerEndpointDiscoverer.class);
Expand All @@ -109,11 +110,13 @@ void webApplicationConfiguresExposeExcludePropertyEndpointFilter() {
}

@Test
@SuppressWarnings("removal")
void contextShouldConfigureServletEndpointDiscoverer() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ServletEndpointDiscoverer.class));
}

@Test
@SuppressWarnings("removal")
void contextWhenNotServletShouldNotConfigureServletEndpointDiscoverer() {
new ApplicationContextRunner().withConfiguration(CONFIGURATIONS)
.run((context) -> assertThat(context).doesNotHaveBean(ServletEndpointDiscoverer.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*
* @author Phillip Webb
*/
@SuppressWarnings("removal")
class ControllerEndpointWebFluxIntegrationTests {

private AnnotationConfigReactiveWebApplicationContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static class SecureConfiguration {
}

@RestControllerEndpoint(id = "example")
@SuppressWarnings("removal")
static class ExampleController {

@GetMapping("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ private Class<?>[] getAutoconfigurations(Class<?>... additional) {
}

@ControllerEndpoint(id = "controller")
@SuppressWarnings("removal")
static class TestControllerEndpoint {

}

@RestControllerEndpoint(id = "restcontroller")
@SuppressWarnings("removal")
static class TestRestControllerEndpoint {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ private WebTestClient createWebTestClient(ApplicationContext context) {
}

@ControllerEndpoint(id = "controller")
@SuppressWarnings("removal")
static class TestControllerEndpoint {

}

@RestControllerEndpoint(id = "restcontroller")
@SuppressWarnings("removal")
static class TestRestControllerEndpoint {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private boolean isExposed(WebTestClient client, HttpMethod method, String path)
}

@RestControllerEndpoint(id = "custommvc")
@SuppressWarnings("removal")
static class CustomMvcEndpoint {

@GetMapping("/")
Expand All @@ -200,6 +201,7 @@ String main() {
}

@ServletEndpoint(id = "customservlet")
@SuppressWarnings("removal")
static class CustomServletEndpoint implements Supplier<EndpointServlet> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ static class SecureConfiguration {
}

@ServletEndpoint(id = "servlet")
@SuppressWarnings("removal")
static class TestServletEndpoint implements Supplier<EndpointServlet> {

@Override
Expand All @@ -209,11 +210,13 @@ public EndpointServlet get() {
}

@ControllerEndpoint(id = "controller")
@SuppressWarnings("removal")
static class TestControllerEndpoint {

}

@RestControllerEndpoint(id = "restcontroller")
@SuppressWarnings("removal")
static class TestRestControllerEndpoint {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ static class FooEndpoint {
}

@ServletEndpoint(id = "baz")
@SuppressWarnings("removal")
static class BazServletEndpoint {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Object getAll() {
}

@ServletEndpoint(id = "se1")
@SuppressWarnings("removal")
static class TestServletEndpoint implements Supplier<EndpointServlet> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ static class FooEndpoint {
}

@ServletEndpoint(id = "baz")
@SuppressWarnings("removal")
static class BazServletEndpoint {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ String fail() {
}

@RestControllerEndpoint(id = "failController")
@SuppressWarnings("removal")
static class FailingControllerEndpoint {

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -33,7 +33,9 @@
* @author Phillip Webb
* @author Julio José Gómez Díaz
* @since 2.0.0
* @deprecated since 3.3.0 in favor of {@code @Endpoint} and {@code @WebEndpoint}
*/
@Deprecated(since = "3.3.0", forRemoval = true)
public final class EndpointServlet {

private final Servlet servlet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 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.
Expand All @@ -24,7 +24,10 @@
*
* @author Phillip Webb
* @since 2.0.0
* @deprecated since 3.3.0 in favor of {@code @Endpoint} and {@code @WebEndpoint}
*/
@Deprecated(since = "3.3.0", forRemoval = true)
@SuppressWarnings("removal")
public interface ExposableServletEndpoint extends ExposableEndpoint<Operation>, PathMappedEndpoint {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -35,7 +35,10 @@
* @author Phillip Webb
* @author Madhura Bhave
* @since 2.0.0
* @deprecated since 3.3.0 in favor of {@code @Endpoint} and {@code @WebEndpoint} support
*/
@Deprecated(since = "3.3.0", forRemoval = true)
@SuppressWarnings("removal")
public class ServletEndpointRegistrar implements ServletContextInitializer {

private static final Log logger = LogFactory.getLog(ServletEndpointRegistrar.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -47,12 +47,14 @@
* @since 2.0.0
* @see WebEndpoint
* @see RestControllerEndpoint
* @deprecated since 3.3.0 in favor of {@code @Endpoint} and {@code @WebEndpoint}
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Endpoint
@FilteredEndpoint(ControllerEndpointFilter.class)
@Deprecated(since = "3.3.0", forRemoval = true)
public @interface ControllerEndpoint {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -31,7 +31,6 @@
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
import org.springframework.boot.actuate.endpoint.web.PathMapper;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointDiscoverer.ControllerEndpointDiscovererRuntimeHints;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.core.annotation.MergedAnnotations;
Expand All @@ -43,8 +42,11 @@
*
* @author Phillip Webb
* @since 2.0.0
* @deprecated since 3.3.0 in favor of {@code @Endpoint} and {@code @WebEndpoint} support
*/
@ImportRuntimeHints(ControllerEndpointDiscovererRuntimeHints.class)
@ImportRuntimeHints(ControllerEndpointDiscoverer.ControllerEndpointDiscovererRuntimeHints.class)
@Deprecated(since = "3.3.0", forRemoval = true)
@SuppressWarnings("removal")
public class ControllerEndpointDiscoverer extends EndpointDiscoverer<ExposableControllerEndpoint, Operation>
implements ControllerEndpointsSupplier {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
Expand All @@ -25,6 +25,7 @@
*
* @author Phillip Webb
*/
@SuppressWarnings("removal")
class ControllerEndpointFilter extends DiscovererEndpointFilter {

ControllerEndpointFilter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -32,6 +32,7 @@
*
* @author Phillip Webb
*/
@SuppressWarnings("removal")
class DiscoveredServletEndpoint extends AbstractDiscoveredEndpoint<Operation> implements ExposableServletEndpoint {

private final String rootPath;
Expand Down
Loading

0 comments on commit 647a5ec

Please sign in to comment.