Use default phase 0 for WebSocket messaging
Closes gh-27519
This commit is contained in:
@@ -276,7 +276,8 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
|
||||
/**
|
||||
* Set the phase that this handler should run in.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with
|
||||
* {@code @EnableWebSocketMessageBroker} configuration it is set to 0.
|
||||
* @since 6.1.4
|
||||
*/
|
||||
public void setPhase(int phase) {
|
||||
|
||||
@@ -202,7 +202,8 @@ public abstract class AbstractBrokerMessageHandler
|
||||
|
||||
/**
|
||||
* Set the phase that this handler should run in.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with
|
||||
* {@code @EnableWebSocketMessageBroker} configuration it is set to 0.
|
||||
* @since 6.1.4
|
||||
*/
|
||||
public void setPhase(int phase) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.SmartApplicationListener;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -197,7 +196,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
}
|
||||
|
||||
protected int initPhase() {
|
||||
return SmartLifecycle.DEFAULT_PHASE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -159,7 +159,8 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
|
||||
|
||||
/**
|
||||
* Set the phase that this handler should run in.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with
|
||||
* {@code @EnableWebSocketMessageBroker} configuration it is set to 0.
|
||||
* @since 6.1.4
|
||||
*/
|
||||
public void setPhase(int phase) {
|
||||
|
||||
@@ -117,11 +117,9 @@ public interface WebSocketMessageBrokerConfigurer {
|
||||
* handling beans of type {@link SmartLifecycle} should run in.
|
||||
* <p>The default implementation returns {@code null} which allows other
|
||||
* configurers to decide. As soon as any configurer returns a value, that
|
||||
* value is used. If no configurer returns a value, then by default
|
||||
* {@link SmartLifecycle#DEFAULT_PHASE} is used.
|
||||
* value is used. If no configurer returns a value, then 0 is used.
|
||||
* <p>It is recommended to use a phase value such as 0 in order to ensure that
|
||||
* components start before the web server in Spring Boot application. In 6.2.0,
|
||||
* the default used will change to 0.
|
||||
* components start before the web server in Spring Boot application.
|
||||
* @since 6.1.4
|
||||
* @see SmartLifecycle
|
||||
*/
|
||||
|
||||
@@ -254,7 +254,8 @@ public class SubProtocolWebSocketHandler
|
||||
|
||||
/**
|
||||
* Set the phase that this handler should run in.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with
|
||||
* {@code @EnableWebSocketMessageBroker} configuration it is set to 0.
|
||||
* @since 6.1.4
|
||||
*/
|
||||
public void setPhase(int phase) {
|
||||
|
||||
@@ -62,7 +62,8 @@ public class WebSocketHandlerMapping extends SimpleUrlHandlerMapping implements
|
||||
|
||||
/**
|
||||
* Set the phase that this handler should run in.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}.
|
||||
* <p>By default, this is {@link SmartLifecycle#DEFAULT_PHASE}, but with
|
||||
* {@code @EnableWebSocketMessageBroker} configuration it is set to 0.
|
||||
* @since 6.1.4
|
||||
*/
|
||||
public void setPhase(int phase) {
|
||||
|
||||
@@ -212,10 +212,18 @@ class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void lifecyclePhase() {
|
||||
ApplicationContext context = createContext(LifecyclePhaseConfig.class);
|
||||
void lifecyclePhaseDefault() {
|
||||
ApplicationContext context = createContext(TestChannelConfig.class, TestConfigurer.class);
|
||||
assertPhase(context, 0);
|
||||
}
|
||||
|
||||
int phase = 99;
|
||||
@Test
|
||||
void lifecyclePhaseExplicitlySet() {
|
||||
ApplicationContext context = createContext(LifecyclePhaseConfig.class);
|
||||
assertPhase(context, 99);
|
||||
}
|
||||
|
||||
private static void assertPhase(ApplicationContext context, int phase) {
|
||||
Consumer<String> executorTester = beanName ->
|
||||
assertThat(context.getBean(beanName, ThreadPoolTaskExecutor.class).getPhase()).isEqualTo(phase);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user