This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 4506648 Bug fixes (#5351)
4506648 is described below
commit 45066480b5852f8882c0bddbfe9a106cc25e7656
Author: Mercy Ma <[email protected]>
AuthorDate: Tue Nov 19 13:25:59 2019 +0800
Bug fixes (#5351)
* Polish apache/dubbo#5306 : [Migration] Upgrade the @since tags in Javadoc
migration cloud native to master
* Polish apache/dubbo#5306 : [Migration] Upgrade the @since tags in Javadoc
migration cloud native to master
* Polish apache/dubbo#5309 : [ISSURE] The beans of Dubbo's Config can't be
found on the ReferenceBean's initialization
* Polish apache/dubbo#5312 : Resolve the demos' issues of zookeeper and
nacos
* Polish apache/dubbo#5313 : [Migration] migrate the code in common module
from cloud-native branch to master
* Polish apache/dubbo#5316 : [Refactor] Replace @EnableDubboConfigBinding
Using spring-context-support
* Polish apache/dubbo#5317 : [Refactor] Refactor
ReferenceAnnotationBeanPostProcessor using Alibaba spring-context-suuport API
* Polish apache/dubbo#5321 : Remove BeanFactoryUtils
* Polish apache/dubbo#5321 : Remove AnnotatedBeanDefinitionRegistryUtils
* Polish apache/dubbo#5321 : Remove AnnotationUtils
* Polish apache/dubbo#5321 : Remove ClassUtils
* Polish apache/dubbo#5321 : Remove BeanRegistrar
* Polish apache/dubbo#5321 : Remove ObjectUtils
* Polish apache/dubbo#5321 : Remove PropertySourcesUtils
* Polish apache/dubbo#5325 : [Migration] To migrate dubbo-metadata-api from
cloud-native branch
* Polish apache/dubbo#5326 : [Migration] To migrate
dubbo-metadata-processor from cloud-native branch
* Polish apache/dubbo#5329 : [Feature] To add the default metadata into
ServiceInstance
* Polish apache/dubbo#5339 : [Refactor] Refactor the DynamicConfiguration
interface
* Polish bugfix
* Fixes test cases
* Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5
# Conflicts:
#
dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
#
dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
* Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5
# Conflicts:
#
dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
#
dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
---
.../DynamicConfigurationFactoryTest.java | 2 +-
.../FileSystemDynamicConfigurationFactoryTest.java | 7 +-
.../file/FileSystemDynamicConfigurationTest.java | 300 ++++++++++-----------
.../org/apache/dubbo/common/utils/StackTest.java | 2 +-
dubbo-config/dubbo-config-api/pom.xml | 15 ++
.../NacosDubboServiceProviderBootstrap.java | 2 +-
.../apache/dubbo/config/spring/ServiceBean.java | 25 +-
.../spring/extension/SpringExtensionFactory.java | 43 +--
.../org/apache/dubbo/config/spring/ConfigTest.java | 2 +-
.../properties/DefaultDubboConfigBinderTest.java | 2 +-
.../{dubbo.properties => dubbo-binder.properties} | 0
.../ZookeeperDynamicConfigurationTest.java | 22 +-
12 files changed, 230 insertions(+), 192 deletions(-)
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactoryTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactoryTest.java
index 6bbbcc6..c89091c 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactoryTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactoryTest.java
@@ -34,6 +34,6 @@ public class DynamicConfigurationFactoryTest {
public void testDefaultExtension() {
DynamicConfigurationFactory factory =
getExtensionLoader(DynamicConfigurationFactory.class).getDefaultExtension();
assertEquals(NopDynamicConfigurationFactory.class, factory.getClass());
- assertEquals(factory,
getExtensionLoader(DynamicConfigurationFactory.class).getExtension("nop"));
+ assertEquals(NopDynamicConfigurationFactory.class,
getExtensionLoader(DynamicConfigurationFactory.class).getExtension("nop").getClass());
}
}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationFactoryTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationFactoryTest.java
index 86d6d17..9e8991d 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationFactoryTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationFactoryTest.java
@@ -16,9 +16,7 @@
*/
package org.apache.dubbo.common.config.configcenter.file;
-import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
-import org.apache.dubbo.common.config.configcenter.nop.NopDynamicConfiguration;
import org.junit.jupiter.api.Test;
@@ -33,9 +31,6 @@ public class FileSystemDynamicConfigurationFactoryTest {
@Test
public void testGetFactory() {
- DynamicConfigurationFactory factory =
DynamicConfigurationFactory.getDynamicConfigurationFactory("not-exists");
- assertEquals(factory,
DynamicConfigurationFactory.getDynamicConfigurationFactory("nop"));
- assertEquals(factory.getDynamicConfiguration(URL.valueOf("dummy")),
factory.getDynamicConfiguration(URL.valueOf("dummy")));
- assertEquals(NopDynamicConfiguration.class,
factory.getDynamicConfiguration(URL.valueOf("dummy")).getClass());
+ assertEquals(FileSystemDynamicConfigurationFactory.class,
DynamicConfigurationFactory.getDynamicConfigurationFactory("file").getClass());
}
}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
index a5b4f51..1422ba6 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
@@ -1,150 +1,150 @@
-///*
-// * Licensed to the Apache Software Foundation (ASF) under one or more
-// * contributor license agreements. See the NOTICE file distributed with
-// * this work for additional information regarding copyright ownership.
-// * The ASF licenses this file to You under the Apache License, Version 2.0
-// * (the "License"); you may not use this file except in compliance with
-// * the License. You may obtain a copy of the License at
-// *
-// * http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing, software
-// * distributed under the License is distributed on an "AS IS" BASIS,
-// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// * See the License for the specific language governing permissions and
-// * limitations under the License.
-// */
-//package org.apache.dubbo.common.config.configcenter.file;
-//
-//import org.apache.dubbo.common.URL;
-//
-//import org.apache.commons.io.FileUtils;
-//import org.junit.jupiter.api.AfterEach;
-//import org.junit.jupiter.api.BeforeEach;
-//import org.junit.jupiter.api.Test;
-//
-//import java.io.File;
-//import java.util.concurrent.ThreadPoolExecutor;
-//import java.util.concurrent.atomic.AtomicBoolean;
-//
-//import static org.apache.commons.io.FileUtils.deleteQuietly;
-//import static org.apache.dubbo.common.URL.valueOf;
-//import static
org.apache.dubbo.common.config.configcenter.DynamicConfiguration.DEFAULT_GROUP;
-//import static
org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration.CONFIG_CENTER_DIR_PARAM_NAME;
-//import static org.junit.jupiter.api.Assertions.assertEquals;
-//import static org.junit.jupiter.api.Assertions.assertNotNull;
-//import static org.junit.jupiter.api.Assertions.assertNull;
-//import static org.junit.jupiter.api.Assertions.assertTrue;
-//
-///**
-// * {@link FileSystemDynamicConfiguration} Test
-// */
-//public class FileSystemDynamicConfigurationTest {
-//
-// private FileSystemDynamicConfiguration configuration;
-//
-// private static final String KEY = "abc-def-ghi";
-//
-// private static final String CONTENT = "Hello,World";
-//
-// @BeforeEach
-// public void init() {
-// File rootDirectory = new File(getClassPath(), "config-center");
-// rootDirectory.mkdirs();
-// URL url =
valueOf("dubbo://127.0.0.1:20880").addParameter(CONFIG_CENTER_DIR_PARAM_NAME,
rootDirectory.getAbsolutePath());
-// configuration = new FileSystemDynamicConfiguration(url);
-// deleteQuietly(configuration.getRootDirectory());
-// }
-//
-// @AfterEach
-// public void destroy() throws Exception {
-// configuration.close();
-// }
-//
-// private String getClassPath() {
-// return
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
-// }
-//
-// @Test
-// public void testInit() {
-//
-// assertEquals(new File(getClassPath(), "config-center"),
configuration.getRootDirectory());
-// assertEquals("UTF-8", configuration.getEncoding());
-// assertEquals(ThreadPoolExecutor.class,
configuration.getWorkersThreadPool().getClass());
-// assertEquals(1,
(configuration.getWorkersThreadPool()).getCorePoolSize());
-// assertEquals(1,
(configuration.getWorkersThreadPool()).getMaximumPoolSize());
-// assertNotNull(configuration.getWatchEventsLoopThreadPool());
-// assertEquals(1,
(configuration.getWatchEventsLoopThreadPool()).getCorePoolSize());
-// assertEquals(1,
(configuration.getWatchEventsLoopThreadPool()).getMaximumPoolSize());
-//
-// if (configuration.isBasedPoolingWatchService()) {
-// assertEquals(2, configuration.getDelay());
-// } else {
-// assertNull(configuration.getDelay());
-// }
-// }
-//
-// @Test
-// public void testPublishAndGetConfig() {
-// assertTrue(configuration.publishConfig(KEY, CONTENT));
-// assertTrue(configuration.publishConfig(KEY, CONTENT));
-// assertTrue(configuration.publishConfig(KEY, CONTENT));
-// assertEquals(CONTENT, configuration.getConfig(KEY, DEFAULT_GROUP));
-// }
-//
-// @Test
-// public void testAddAndRemoveListener() throws InterruptedException {
-//
-// configuration.publishConfig(KEY, "A");
-//
-// AtomicBoolean processedEvent = new AtomicBoolean();
-//
-// configuration.addListener(KEY, event -> {
-//
-// processedEvent.set(true);
-// assertEquals(KEY, event.getKey());
-// System.out.printf("[%s] " + event + "\n",
Thread.currentThread().getName());
-// });
-//
-//
-// configuration.publishConfig(KEY, "B");
-// while (!processedEvent.get()) {
-// Thread.sleep(1 * 1000L);
-// }
-//
-// processedEvent.set(false);
-// configuration.publishConfig(KEY, "C");
-// while (!processedEvent.get()) {
-// Thread.sleep(1 * 1000L);
-// }
-//
-// processedEvent.set(false);
-// configuration.publishConfig(KEY, "D");
-// while (!processedEvent.get()) {
-// Thread.sleep(1 * 1000L);
-// }
-//
-// configuration.addListener("test", "test", event -> {
-// processedEvent.set(true);
-// assertEquals("test", event.getKey());
-// System.out.printf("[%s] " + event + "\n",
Thread.currentThread().getName());
-// });
-// processedEvent.set(false);
-// configuration.publishConfig("test", "test", "TEST");
-// while (!processedEvent.get()) {
-// Thread.sleep(1 * 1000L);
-// }
-//
-// configuration.publishConfig("test", "test", "TEST");
-// configuration.publishConfig("test", "test", "TEST");
-// configuration.publishConfig("test", "test", "TEST");
-//
-//
-// processedEvent.set(false);
-// File keyFile = configuration.configFile(KEY, DEFAULT_GROUP);
-// FileUtils.deleteQuietly(keyFile);
-// while (!processedEvent.get()) {
-// Thread.sleep(1 * 1000L);
-// }
-// }
-//}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.config.configcenter.file;
+
+import org.apache.dubbo.common.URL;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.apache.commons.io.FileUtils.deleteQuietly;
+import static org.apache.dubbo.common.URL.valueOf;
+import static
org.apache.dubbo.common.config.configcenter.DynamicConfiguration.DEFAULT_GROUP;
+import static
org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration.CONFIG_CENTER_DIR_PARAM_NAME;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@link FileSystemDynamicConfiguration} Test
+ */
+public class FileSystemDynamicConfigurationTest {
+
+ private FileSystemDynamicConfiguration configuration;
+
+ private static final String KEY = "abc-def-ghi";
+
+ private static final String CONTENT = "Hello,World";
+
+ @BeforeEach
+ public void init() {
+ File rootDirectory = new File(getClassPath(), "config-center");
+ rootDirectory.mkdirs();
+ URL url =
valueOf("dubbo://127.0.0.1:20880").addParameter(CONFIG_CENTER_DIR_PARAM_NAME,
rootDirectory.getAbsolutePath());
+ configuration = new FileSystemDynamicConfiguration(url);
+ deleteQuietly(configuration.getRootDirectory());
+ }
+
+ @AfterEach
+ public void destroy() throws Exception {
+ configuration.close();
+ }
+
+ private String getClassPath() {
+ return
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
+ }
+
+ @Test
+ public void testInit() {
+
+ assertEquals(new File(getClassPath(), "config-center"),
configuration.getRootDirectory());
+ assertEquals("UTF-8", configuration.getEncoding());
+ assertEquals(ThreadPoolExecutor.class,
configuration.getWorkersThreadPool().getClass());
+ assertEquals(1,
(configuration.getWorkersThreadPool()).getCorePoolSize());
+ assertEquals(1,
(configuration.getWorkersThreadPool()).getMaximumPoolSize());
+ assertNotNull(configuration.getWatchEventsLoopThreadPool());
+ assertEquals(1,
(configuration.getWatchEventsLoopThreadPool()).getCorePoolSize());
+ assertEquals(1,
(configuration.getWatchEventsLoopThreadPool()).getMaximumPoolSize());
+
+ if (configuration.isBasedPoolingWatchService()) {
+ assertEquals(2, configuration.getDelay());
+ } else {
+ assertNull(configuration.getDelay());
+ }
+ }
+
+ @Test
+ public void testPublishAndGetConfig() {
+ assertTrue(configuration.publishConfig(KEY, CONTENT));
+ assertTrue(configuration.publishConfig(KEY, CONTENT));
+ assertTrue(configuration.publishConfig(KEY, CONTENT));
+ assertEquals(CONTENT, configuration.getConfig(KEY, DEFAULT_GROUP));
+ }
+
+ @Test
+ public void testAddAndRemoveListener() throws InterruptedException {
+
+ configuration.publishConfig(KEY, "A");
+
+ AtomicBoolean processedEvent = new AtomicBoolean();
+
+ configuration.addListener(KEY, event -> {
+
+ processedEvent.set(true);
+ assertEquals(KEY, event.getKey());
+ System.out.printf("[%s] " + event + "\n",
Thread.currentThread().getName());
+ });
+
+
+ configuration.publishConfig(KEY, "B");
+ while (!processedEvent.get()) {
+ Thread.sleep(1 * 1000L);
+ }
+
+ processedEvent.set(false);
+ configuration.publishConfig(KEY, "C");
+ while (!processedEvent.get()) {
+ Thread.sleep(1 * 1000L);
+ }
+
+ processedEvent.set(false);
+ configuration.publishConfig(KEY, "D");
+ while (!processedEvent.get()) {
+ Thread.sleep(1 * 1000L);
+ }
+
+ configuration.addListener("test", "test", event -> {
+ processedEvent.set(true);
+ assertEquals("test", event.getKey());
+ System.out.printf("[%s] " + event + "\n",
Thread.currentThread().getName());
+ });
+ processedEvent.set(false);
+ configuration.publishConfig("test", "test", "TEST");
+ while (!processedEvent.get()) {
+ Thread.sleep(1 * 1000L);
+ }
+
+ configuration.publishConfig("test", "test", "TEST");
+ configuration.publishConfig("test", "test", "TEST");
+ configuration.publishConfig("test", "test", "TEST");
+
+
+ processedEvent.set(false);
+ File keyFile = configuration.configFile(KEY, DEFAULT_GROUP);
+ FileUtils.deleteQuietly(keyFile);
+ while (!processedEvent.get()) {
+ Thread.sleep(1 * 1000L);
+ }
+ }
+}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StackTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StackTest.java
index 6a32f22..a51bc78 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StackTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StackTest.java
@@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test;
import java.util.EmptyStackException;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
public class StackTest {
@Test
diff --git a/dubbo-config/dubbo-config-api/pom.xml
b/dubbo-config/dubbo-config-api/pom.xml
index 5937993..1330179 100644
--- a/dubbo-config/dubbo-config-api/pom.xml
+++ b/dubbo-config/dubbo-config-api/pom.xml
@@ -186,5 +186,20 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-consul</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+
</dependencies>
</project>
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceProviderBootstrap.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceProviderBootstrap.java
index 763cfdf..35ed723 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceProviderBootstrap.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceProviderBootstrap.java
@@ -34,7 +34,7 @@ public class NacosDubboServiceProviderBootstrap {
DubboBootstrap.getInstance()
.application(applicationConfig)
// Zookeeper in service registry type
- .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry-type=service"))
+ .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry-type=service").useAsConfigCenter(true))
// Nacos
// .registry("nacos", builder ->
builder.address("nacos://127.0.0.1:8848?registry.type=service"))
//
.registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry.type=service").build())
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java
index ee8aa33..6f75535 100644
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java
+++
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java
@@ -30,6 +30,10 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+import java.util.Objects;
/**
* ServiceFactoryBean
@@ -37,7 +41,7 @@ import
org.springframework.context.ApplicationEventPublisherAware;
* @export
*/
public class ServiceBean<T> extends ServiceConfig<T> implements
InitializingBean, DisposableBean,
- ApplicationContextAware, BeanNameAware,
+ ApplicationContextAware, BeanNameAware,
ApplicationListener<ContextRefreshedEvent>,
ApplicationEventPublisherAware {
@@ -143,4 +147,23 @@ public class ServiceBean<T> extends ServiceConfig<T>
implements InitializingBean
public void setApplicationEventPublisher(ApplicationEventPublisher
applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
+
+ @Override
+ public void onApplicationEvent(ContextRefreshedEvent event) {
+
+ if (!isOriginEventSource(event)) {
+ return;
+ }
+
+ if (!isExported() && !isUnexported()) {
+ if (logger.isInfoEnabled()) {
+ logger.info("The service ready on spring started. service: " +
getInterface());
+ }
+ export();
+ }
+ }
+
+ private boolean isOriginEventSource(ContextRefreshedEvent event) {
+ return Objects.equals(applicationContext,
event.getApplicationContext());
+ }
}
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
index 863a677..7ddc273 100644
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
+++
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
@@ -24,8 +24,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.config.DubboShutdownHook;
import org.apache.dubbo.config.spring.util.ApplicationContextUtils;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
+import com.alibaba.spring.util.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
@@ -75,11 +74,15 @@ public class SpringExtensionFactory implements
ExtensionFactory {
}
for (ApplicationContext context : CONTEXTS) {
- if (context.containsBean(name)) {
- Object bean = context.getBean(name);
- if (type.isInstance(bean)) {
- return (T) bean;
- }
+// if (context.containsBean(name)) {
+// Object bean = context.getBean(name);
+// if (type.isInstance(bean)) {
+// return (T) bean;
+// }
+// }
+ T bean = BeanFactoryUtils.getOptionalBean(context, name, type);
+ if (bean != null) {
+ return bean;
}
}
@@ -89,19 +92,19 @@ public class SpringExtensionFactory implements
ExtensionFactory {
return null;
}
- for (ApplicationContext context : CONTEXTS) {
- try {
- return context.getBean(type);
- } catch (NoUniqueBeanDefinitionException multiBeanExe) {
- logger.warn("Find more than 1 spring extensions (beans) of
type " + type.getName() + ", will stop auto injection. Please make sure you
have specified the concrete parameter type and there's only one extension of
that type.");
- } catch (NoSuchBeanDefinitionException noBeanExe) {
- if (logger.isDebugEnabled()) {
- logger.debug("Error when get spring extension(bean) for
type:" + type.getName(), noBeanExe);
- }
- }
- }
-
- logger.warn("No spring extension (bean) named:" + name + ", type:" +
type.getName() + " found, stop get bean.");
+// for (ApplicationContext context : CONTEXTS) {
+// try {
+// return context.getBean(type);
+// } catch (NoUniqueBeanDefinitionException multiBeanExe) {
+// logger.warn("Find more than 1 spring extensions (beans) of
type " + type.getName() + ", will stop auto injection. Please make sure you
have specified the concrete parameter type and there's only one extension of
that type.");
+// } catch (NoSuchBeanDefinitionException noBeanExe) {
+// if (logger.isDebugEnabled()) {
+// logger.debug("Error when get spring extension(bean) for
type:" + type.getName(), noBeanExe);
+// }
+// }
+// }
+//
+// logger.warn("No spring extension (bean) named:" + name + ", type:" +
type.getName() + " found, stop get bean.");
return null;
}
diff --git
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
index 9f50a0c..6269258 100644
---
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
+++
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
@@ -839,7 +839,7 @@ public class ConfigTest {
URL url = service.getExportedUrls().get(0);
// from api
assertEquals("aaa", url.getParameter("application"));
- // from dubbo.properties
+ // from dubbo-binder.properties
assertEquals("world", url.getParameter("owner"));
// from system property
assertEquals(1234, url.getPort());
diff --git
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java
index 030fbc8..aea9fb9 100644
---
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java
+++
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java
@@ -30,7 +30,7 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@TestPropertySource(locations = "classpath:/dubbo.properties")
+@TestPropertySource(locations = "classpath:/dubbo-binder.properties")
@ContextConfiguration(classes = DefaultDubboConfigBinder.class)
public class DefaultDubboConfigBinderTest {
diff --git
a/dubbo-config/dubbo-config-spring/src/test/resources/dubbo.properties
b/dubbo-config/dubbo-config-spring/src/test/resources/dubbo-binder.properties
similarity index 100%
rename from dubbo-config/dubbo-config-spring/src/test/resources/dubbo.properties
rename to
dubbo-config/dubbo-config-spring/src/test/resources/dubbo-binder.properties
diff --git
a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
index 50fac3d..3c06fbe 100644
---
a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
+++
b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
@@ -128,12 +129,12 @@ public class ZookeeperDynamicConfigurationTest {
@Test
public void testPublishConfig() {
- String group = "user-service";
- String key = "org.apache.dubbo.service.UserService";
- String app = "test";
+ String key = "user-service";
+ String group = "org.apache.dubbo.service.UserService";
+ String content = "test";
- assertTrue(configuration.publishConfig(app, group + "/" + key, "non"));
- assertEquals("non", configuration.getProperties(app, group + "/" +
key));
+ assertTrue(configuration.publishConfig(key, group, content));
+ assertEquals("test", configuration.getProperties(key, group));
}
@Test
@@ -141,15 +142,16 @@ public class ZookeeperDynamicConfigurationTest {
String group = "mapping";
String key = "org.apache.dubbo.service.UserService";
- String app = "app1";
+ String content = "app1";
String key2 = "org.apache.dubbo.service.UserService2";
- assertTrue(configuration.publishConfig(app, group + "/" + key, ""));
- assertTrue(configuration.publishConfig(app, group + "/" + key2, ""));
+ assertTrue(configuration.publishConfig(key, group, content));
+ assertTrue(configuration.publishConfig(key2, group, content));
+
+ Set<String> configKeys = configuration.getConfigKeys(group);
- assertEquals(new TreeSet(asList(key, key2)),
configuration.getConfigKeys(group));
- assertEquals(new TreeSet(asList(app)),
configuration.getConfigKeys(group + "/" + key));
+ assertEquals(new TreeSet(asList(key, key2)), configKeys);
}
private class TestListener implements ConfigurationListener {