Introduce a public constant for the WebServerStartStopLifecycle's phase

This commit also moves the constant for the phase of
WebServerGracefulShutdownLifecycle to WebServerApplicationContext.

Closes gh-45572
This commit is contained in:
Stéphane Nicoll
2025-05-26 16:32:42 +02:00
parent e0d10d7d8c
commit a0a39abb49
5 changed files with 29 additions and 12 deletions

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.
@@ -34,7 +34,6 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.web.context.ConfigurableWebServerApplicationContext;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEvent;
@@ -115,7 +114,7 @@ class ChildManagementContextInitializer implements BeanRegistrationAotProcessor,
@Override
public int getPhase() {
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 512;
return WebServerApplicationContext.GRACEFUL_SHUTDOWN_PHASE - 512;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 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.
@@ -18,6 +18,7 @@ package org.springframework.boot.web.context;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.util.ObjectUtils;
/**
@@ -29,6 +30,20 @@ import org.springframework.util.ObjectUtils;
*/
public interface WebServerApplicationContext extends ApplicationContext {
/**
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
* of the web server is performed.
* @since 4.0.0
*/
int GRACEFUL_SHUTDOWN_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
/**
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which starting and
* stopping of the web server is performed.
* @since 4.0.0
*/
int START_STOP_LIFECYCLE_PHASE = GRACEFUL_SHUTDOWN_PHASE - 1024;
/**
* Returns the {@link WebServer} that was created by the context or {@code null} if
* the server has not yet been created.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 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.
@@ -30,7 +30,10 @@ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle
/**
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
* of the web server is performed.
* @deprecated as of 4.0.0 in favor of
* {@link WebServerApplicationContext#GRACEFUL_SHUTDOWN_PHASE}
*/
@Deprecated(since = "4.0.0", forRemoval = true)
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
private final WebServer webServer;
@@ -69,7 +72,7 @@ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle
@Override
public int getPhase() {
return SMART_LIFECYCLE_PHASE;
return WebServerApplicationContext.GRACEFUL_SHUTDOWN_PHASE;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 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.
@@ -16,7 +16,7 @@
package org.springframework.boot.web.reactive.context;
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.SmartLifecycle;
@@ -55,7 +55,7 @@ class WebServerStartStopLifecycle implements SmartLifecycle {
@Override
public int getPhase() {
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
return WebServerApplicationContext.START_STOP_LIFECYCLE_PHASE;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 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.
@@ -16,7 +16,7 @@
package org.springframework.boot.web.servlet.context;
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.SmartLifecycle;
@@ -60,7 +60,7 @@ class WebServerStartStopLifecycle implements SmartLifecycle {
@Override
public int getPhase() {
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
return WebServerApplicationContext.START_STOP_LIFECYCLE_PHASE;
}
}