diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index d1ea945452..38582a7476 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -110,6 +110,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto */ public static final String DEFAULT_PROTOCOL = "org.apache.coyote.http11.Http11NioProtocol"; + private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null; + private File baseDirectory; private List engineValves = new ArrayList<>(); @@ -164,9 +166,14 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto } private static List getDefaultLifecycleListeners() { - AprLifecycleListener aprLifecycleListener = new AprLifecycleListener(); - return AprLifecycleListener.isAprAvailable() ? new ArrayList<>(Arrays.asList(aprLifecycleListener)) - : new ArrayList<>(); + ArrayList lifecycleListeners = new ArrayList<>(); + if (!IN_NATIVE_IMAGE) { + AprLifecycleListener aprLifecycleListener = new AprLifecycleListener(); + if (AprLifecycleListener.isAprAvailable()) { + lifecycleListeners.add(aprLifecycleListener); + } + } + return lifecycleListeners; } @Override