Skip to content

Commit a0a39ab

Browse files
committed
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
1 parent e0d10d7 commit a0a39ab

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,6 @@
3434
import org.springframework.boot.context.event.ApplicationFailedEvent;
3535
import org.springframework.boot.web.context.ConfigurableWebServerApplicationContext;
3636
import org.springframework.boot.web.context.WebServerApplicationContext;
37-
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
3837
import org.springframework.context.ApplicationContext;
3938
import org.springframework.context.ApplicationContextInitializer;
4039
import org.springframework.context.ApplicationEvent;
@@ -115,7 +114,7 @@ public boolean isRunning() {
115114

116115
@Override
117116
public int getPhase() {
118-
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 512;
117+
return WebServerApplicationContext.GRACEFUL_SHUTDOWN_PHASE - 512;
119118
}
120119

121120
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerApplicationContext.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.boot.web.server.WebServer;
2020
import org.springframework.context.ApplicationContext;
21+
import org.springframework.context.SmartLifecycle;
2122
import org.springframework.util.ObjectUtils;
2223

2324
/**
@@ -29,6 +30,20 @@
2930
*/
3031
public interface WebServerApplicationContext extends ApplicationContext {
3132

33+
/**
34+
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
35+
* of the web server is performed.
36+
* @since 4.0.0
37+
*/
38+
int GRACEFUL_SHUTDOWN_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
39+
40+
/**
41+
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which starting and
42+
* stopping of the web server is performed.
43+
* @since 4.0.0
44+
*/
45+
int START_STOP_LIFECYCLE_PHASE = GRACEFUL_SHUTDOWN_PHASE - 1024;
46+
3247
/**
3348
* Returns the {@link WebServer} that was created by the context or {@code null} if
3449
* the server has not yet been created.

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerGracefulShutdownLifecycle.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,10 @@ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle
3030
/**
3131
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
3232
* of the web server is performed.
33+
* @deprecated as of 4.0.0 in favor of
34+
* {@link WebServerApplicationContext#GRACEFUL_SHUTDOWN_PHASE}
3335
*/
36+
@Deprecated(since = "4.0.0", forRemoval = true)
3437
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
3538

3639
private final WebServer webServer;
@@ -69,7 +72,7 @@ public boolean isRunning() {
6972

7073
@Override
7174
public int getPhase() {
72-
return SMART_LIFECYCLE_PHASE;
75+
return WebServerApplicationContext.GRACEFUL_SHUTDOWN_PHASE;
7376
}
7477

7578
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/WebServerStartStopLifecycle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.web.reactive.context;
1818

19-
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
19+
import org.springframework.boot.web.context.WebServerApplicationContext;
2020
import org.springframework.boot.web.server.WebServer;
2121
import org.springframework.context.SmartLifecycle;
2222

@@ -55,7 +55,7 @@ public boolean isRunning() {
5555

5656
@Override
5757
public int getPhase() {
58-
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
58+
return WebServerApplicationContext.START_STOP_LIFECYCLE_PHASE;
5959
}
6060

6161
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/WebServerStartStopLifecycle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.web.servlet.context;
1818

19-
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
19+
import org.springframework.boot.web.context.WebServerApplicationContext;
2020
import org.springframework.boot.web.server.WebServer;
2121
import org.springframework.context.SmartLifecycle;
2222

@@ -60,7 +60,7 @@ public boolean isRunning() {
6060

6161
@Override
6262
public int getPhase() {
63-
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
63+
return WebServerApplicationContext.START_STOP_LIFECYCLE_PHASE;
6464
}
6565

6666
}

0 commit comments

Comments
 (0)