diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml
index 3d96b6ac0955764a0fe5cea99c6902f2d4d47d18..8d6afff735261ff5ec40c01ff9ea7ea38df4bf39 100644
--- a/dubbo-config/dubbo-config-api/pom.xml
+++ b/dubbo-config/dubbo-config-api/pom.xml
@@ -99,5 +99,11 @@
hibernate-validator
test
+
+ com.alibaba
+ dubbo-registry-multicast
+ ${project.parent.version}
+ test
+
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java
index 5ef3fd04d6a0971c7f168e47d5a9d0a9682f5dbc..d5171c85e671015a30a86905299e8f21494204df 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java
@@ -328,14 +328,18 @@ public class ReferenceConfig extends AbstractReferenceConfig {
private T createProxy(Map map) {
URL tmpUrl = new URL("temp", "localhost", 0, map);
final boolean isJvmRefer;
- if (url != null && url.length() > 0) { //指定URL的情况下,不做本地引用
- isJvmRefer = false;
- } else if (InjvmProtocol.getInjvmProtocol().isInjvmRefer(tmpUrl)) {
- //默认情况下如果本地有服务暴露,则引用本地服务.
- isJvmRefer = true;
- } else {
- isJvmRefer = false;
- }
+ if (isInjvm() == null) {
+ if (url != null && url.length() > 0) { //指定URL的情况下,不做本地引用
+ isJvmRefer = false;
+ } else if (InjvmProtocol.getInjvmProtocol().isInjvmRefer(tmpUrl)) {
+ //默认情况下如果本地有服务暴露,则引用本地服务.
+ isJvmRefer = true;
+ } else {
+ isJvmRefer = false;
+ }
+ } else {
+ isJvmRefer = isInjvm().booleanValue();
+ }
if (isJvmRefer) {
URL url = new URL(Constants.LOCAL_PROTOCOL, NetUtils.LOCALHOST, 0, interfaceClass.getName()).addParameters(map);
diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..7908a42512172642c017fd8a37ff54c8e25c749d
--- /dev/null
+++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 1999-2012 Alibaba Group.
+ *
+ * Licensed 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 com.alibaba.dubbo.config;
+
+import org.junit.Test;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.config.api.DemoService;
+import com.alibaba.dubbo.config.provider.impl.DemoServiceImpl;
+
+import junit.framework.Assert;
+
+/**
+ * @author kimi
+ */
+public class ReferenceConfigTest {
+
+ @Test
+ public void testInjvm() throws Exception {
+ ApplicationConfig application = new ApplicationConfig();
+ application.setName("test-protocol-random-port");
+
+ RegistryConfig registry = new RegistryConfig();
+ registry.setAddress("multicast://224.5.6.7:1234");
+
+ ProtocolConfig protocol = new ProtocolConfig();
+ protocol.setName("dubbo");
+
+ ServiceConfig demoService;
+ demoService = new ServiceConfig();
+ demoService.setInterface(DemoService.class);
+ demoService.setRef(new DemoServiceImpl());
+ demoService.setApplication(application);
+ demoService.setRegistry(registry);
+ demoService.setProtocol(protocol);
+
+ ReferenceConfig rc = new ReferenceConfig();
+ rc.setApplication(application);
+ rc.setRegistry(registry);
+ rc.setInterface(DemoService.class.getName());
+ rc.setInjvm(false);
+
+ try {
+ demoService.export();
+ rc.get();
+ Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(
+ rc.getInvoker().getUrl().getProtocol()));
+ } finally {
+ demoService.unexport();
+ }
+ }
+
+}
\ No newline at end of file