diff --git a/CHANGES.md b/CHANGES.md index 60bbe031bb9..15500d3ea59 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java index 444c5aa4637..24376c46512 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java @@ -26,6 +26,8 @@ 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; @@ -33,6 +35,8 @@ import org.springframework.core.type.AnnotationMetadata; public class DefaultApolloConfigRegistrarHelper implements ApolloConfigRegistrarHelper { + private static final Logger logger = LoggerFactory.getLogger( + DefaultApolloConfigRegistrarHelper.class); private Environment environment; @@ -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 @@ -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;