From 01558100d14a874b81473a466b9f5b1abbde1a9f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 22 Jul 2020 06:30:39 +0100 Subject: [PATCH] Do not attempt to use AprLifecycleListener in a native image Closes gh-22485 --- .../tomcat/TomcatServletWebServerFactory.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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