From 55e3ca66e2a4480f6c820daf4b1e78085b82449c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 16 Feb 2021 10:34:34 +0000 Subject: [PATCH] Replace native image system property with call to NativeDetector Closes gh-25303 --- .../boot/autoconfigure/BackgroundPreinitializer.java | 6 +++--- .../web/embedded/tomcat/TomcatServletWebServerFactory.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java index a64699a784a7..d97c57d248c5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.boot.context.event.SpringApplicationEvent; import org.springframework.boot.context.logging.LoggingApplicationListener; import org.springframework.context.ApplicationListener; +import org.springframework.core.NativeDetector; import org.springframework.core.annotation.Order; import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; @@ -67,8 +68,7 @@ public class BackgroundPreinitializer implements ApplicationListener 1; } 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 1dfd70ff987d..84a099284234 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.NativeDetector; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -110,8 +111,6 @@ 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<>(); @@ -169,7 +168,7 @@ public TomcatServletWebServerFactory(String contextPath, int port) { private static List getDefaultLifecycleListeners() { ArrayList lifecycleListeners = new ArrayList<>(); - if (!IN_NATIVE_IMAGE) { + if (!NativeDetector.inNativeImage()) { AprLifecycleListener aprLifecycleListener = new AprLifecycleListener(); if (AprLifecycleListener.isAprAvailable()) { lifecycleListeners.add(aprLifecycleListener);