From a6c139e0ceae109bfa60be94676bb3871e7b58fe Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Wed, 15 May 2024 11:56:22 +0800 Subject: [PATCH] fix:add warn log to ApplicationContextAwareUtils. --- .../cloud/common/util/ApplicationContextAwareUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java index be90be2f4..60421b02c 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ApplicationContextAwareUtils.java @@ -18,6 +18,8 @@ package com.tencent.cloud.common.util; import com.tencent.polaris.api.utils.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -31,6 +33,8 @@ import org.springframework.lang.NonNull; */ public class ApplicationContextAwareUtils implements ApplicationContextAware { + private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationContextAwareUtils.class); + private static ApplicationContext applicationContext; /** @@ -55,6 +59,7 @@ public class ApplicationContextAwareUtils implements ApplicationContextAware { if (applicationContext != null) { return applicationContext.getEnvironment().getProperty(key); } + LOGGER.warn("applicationContext is null, try to get property from System.getenv or System.getProperty"); String property = System.getenv(key); if (StringUtils.isBlank(property)) { property = System.getProperty(key); @@ -72,6 +77,7 @@ public class ApplicationContextAwareUtils implements ApplicationContextAware { if (applicationContext != null) { return applicationContext.getEnvironment().getProperty(key, defaultValue); } + LOGGER.warn("applicationContext is null, try to get property from System.getenv or System.getProperty"); String property = System.getenv(key); if (StringUtils.isBlank(property)) { property = System.getProperty(key, defaultValue);