Skip to content

Commit 4cd9e90

Browse files
committed
CommonsExecWebServer guarantees startup
The CommonsExecWebServer is async but is started before ApplicationContext startup completes Closes gh-82
1 parent 1dbee90 commit 4cd9e90

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/CommonsExecWebServerFactoryBean.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.beans.factory.BeanNameAware;
3030
import org.springframework.beans.factory.DisposableBean;
3131
import org.springframework.beans.factory.SmartFactoryBean;
32+
import org.springframework.beans.factory.SmartInitializingSingleton;
3233
import org.springframework.experimental.boot.server.exec.imports.GenericSpringBootApplicationMain;
3334
import org.springframework.util.Assert;
3435
import org.springframework.util.ClassUtils;
@@ -44,7 +45,7 @@
4445
* @author Daniel Garnier-Moiroux
4546
*/
4647
public class CommonsExecWebServerFactoryBean
47-
implements SmartFactoryBean<CommonsExecWebServer>, DisposableBean, BeanNameAware {
48+
implements SmartFactoryBean<CommonsExecWebServer>, DisposableBean, BeanNameAware, SmartInitializingSingleton {
4849

4950
private static Log logger = LogFactory.getLog(CommonsExecWebServerFactoryBean.class);
5051

@@ -203,6 +204,18 @@ public void destroy() throws Exception {
203204
}
204205
}
205206

207+
/**
208+
* The server is asynchronous to make ApplicationContext startup faster, but we want
209+
* to ensure that the web server starts before the ApplicationContext startup
210+
* completes.
211+
*/
212+
@Override
213+
public void afterSingletonsInstantiated() {
214+
if (this.webServer != null) {
215+
this.webServer.getPort();
216+
}
217+
}
218+
206219
/**
207220
* The settings for debugging.
208221
*

0 commit comments

Comments
 (0)