Skip to content
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

Fix the NPE occurred when using EnableApolloConfig with Spring 3.1.1 #4180

Merged
merged 1 commit into from
Dec 26, 2021
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Apollo 2.0.0
* [fix gray publish refresh item status](https://github.com/apolloconfig/apollo/pull/4128)
* [Support only show difference keys when compare namespace](https://github.com/apolloconfig/apollo/pull/4165)
* [Fix the issue that property placeholder doesn't work for dubbo reference beans](https://github.com/apolloconfig/apollo/pull/4175)
* [Fix the NPE occurred when using EnableApolloConfig with Spring 3.1.1](https://github.com/apolloconfig/apollo/pull/4180)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotationMetadata;

public class DefaultApolloConfigRegistrarHelper implements ApolloConfigRegistrarHelper {
private static final Logger logger = LoggerFactory.getLogger(
DefaultApolloConfigRegistrarHelper.class);

private Environment environment;

Expand Down Expand Up @@ -62,6 +66,11 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
}

private String[] resolveNamespaces(String[] namespaces) {
// no support for Spring version prior to 3.2.x, see https://github.com/apolloconfig/apollo/issues/4178
if (this.environment == null) {
logNamespacePlaceholderNotSupportedMessage(namespaces);
return namespaces;
}
String[] resolvedNamespaces = new String[namespaces.length];
for (int i = 0; i < namespaces.length; i++) {
// throw IllegalArgumentException if given text is null or if any placeholders are unresolvable
Expand All @@ -70,6 +79,17 @@ private String[] resolveNamespaces(String[] namespaces) {
return resolvedNamespaces;
}

private void logNamespacePlaceholderNotSupportedMessage(String[] namespaces) {
for (String namespace : namespaces) {
if (namespace.contains("${")) {
logger.warn("Namespace placeholder {} is not supported for Spring version prior to 3.2.x,"
+ " see https://github.com/apolloconfig/apollo/issues/4178 for more details.",
namespace);
break;
}
}
}

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
Expand Down