Skip to content

fix:fix ApplicationContextAwareUtils NPE bug. #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
---

- [feat:upgrade jackson version.](https://github.com/Tencent/spring-cloud-tencent/pull/1259)
- [fix:fix ApplicationContextAwareUtils NPE bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1294)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package com.tencent.cloud.common.util;

import com.tencent.polaris.api.utils.StringUtils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
Expand Down Expand Up @@ -50,7 +52,14 @@ public void setApplicationContext(@NonNull ApplicationContext applicationContext
* @return property value
*/
public static String getProperties(String key) {
return applicationContext.getEnvironment().getProperty(key);
if (applicationContext != null) {
return applicationContext.getEnvironment().getProperty(key);
}
String property = System.getenv(key);
if (StringUtils.isBlank(property)) {
property = System.getProperty(key);
}
return property;
}

/**
Expand All @@ -60,6 +69,13 @@ public static String getProperties(String key) {
* @return property value
*/
public static String getProperties(String key, String defaultValue) {
return applicationContext.getEnvironment().getProperty(key, defaultValue);
if (applicationContext != null) {
return applicationContext.getEnvironment().getProperty(key, defaultValue);
}
String property = System.getenv(key);
if (StringUtils.isBlank(property)) {
property = System.getProperty(key, defaultValue);
}
return property;
}
}
Loading