diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java index f9ac0d93d5..8f6120ee6d 100644 --- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java +++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java @@ -16,52 +16,53 @@ package org.springframework.cloud.netflix.eureka.server; -import com.netflix.eureka.EurekaServerConfig; -import jakarta.servlet.ServletContext; +import java.util.concurrent.CompletableFuture; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent; import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent; -import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.SmartLifecycle; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; -import org.springframework.web.context.ServletContextAware; + +import com.netflix.eureka.EurekaServerConfig; + +import jakarta.servlet.ServletContext; /** * @author Dave Syer */ @Configuration(proxyBeanMethods = false) -public class EurekaServerInitializerConfiguration implements ServletContextAware, SmartLifecycle, Ordered { +public class EurekaServerInitializerConfiguration implements SmartLifecycle, Ordered { private static final Log log = LogFactory.getLog(EurekaServerInitializerConfiguration.class); - @Autowired - private EurekaServerConfig eurekaServerConfig; + private static final int ORDER = 1; - private ServletContext servletContext; + private final EurekaServerConfig eurekaServerConfig; - @Autowired - private ApplicationContext applicationContext; + private final ServletContext servletContext; - @Autowired - private EurekaServerBootstrap eurekaServerBootstrap; + private final ApplicationEventPublisher applicationEventPublisher; - private boolean running; + private final EurekaServerBootstrap eurekaServerBootstrap; - private final int order = 1; + private volatile boolean running; - @Override - public void setServletContext(ServletContext servletContext) { + public EurekaServerInitializerConfiguration(EurekaServerConfig eurekaServerConfig, ServletContext servletContext, + ApplicationEventPublisher applicationEventPublisher, EurekaServerBootstrap eurekaServerBootstrap) { + this.eurekaServerConfig = eurekaServerConfig; this.servletContext = servletContext; + this.applicationEventPublisher = applicationEventPublisher; + this.eurekaServerBootstrap = eurekaServerBootstrap; } @Override public void start() { - new Thread(() -> { + CompletableFuture.runAsync(() -> { try { // TODO: is this class even needed now? eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext); @@ -75,7 +76,7 @@ public void start() { // Help! log.error("Could not initialize Eureka servlet context", ex); } - }).start(); + }); } private EurekaServerConfig getEurekaServerConfig() { @@ -83,7 +84,7 @@ private EurekaServerConfig getEurekaServerConfig() { } private void publish(ApplicationEvent event) { - this.applicationContext.publishEvent(event); + this.applicationEventPublisher.publishEvent(event); } @Override @@ -102,14 +103,9 @@ public int getPhase() { return 0; } - @Override - public boolean isAutoStartup() { - return true; - } - @Override public int getOrder() { - return this.order; + return ORDER; } }