diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java index 757f2b50e..b8db4d31a 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java @@ -15,14 +15,15 @@ */ package org.springframework.cloud.alicloud.context.nacos; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import java.util.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener; -import java.util.Properties; +import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; +import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; /** * @author pbting @@ -53,7 +54,7 @@ public class NacosDiscoveryParameterInitListener } // initialize nacos configuration Properties properties = System.getProperties(); - + properties.setProperty("spring.cloud.nacos.discovery.server-mode", "EDAS"); // step 1: set some properties for spring cloud alibaba nacos discovery properties.setProperty("spring.cloud.nacos.discovery.server-addr", ""); properties.setProperty("spring.cloud.nacos.discovery.endpoint", diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java index 709315d8b..e820d4a93 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java @@ -48,7 +48,9 @@ public class StatisticsTaskStarter implements InitializingBean { private static final String NACOS_CONFIG_SERVER_MODE_KEY = "spring.cloud.nacos.config.server-mode"; - private static final String NACOS_CONFIG_SERVER_MODE_VALUE = "EDAS"; + private static final String NACOS_DISCOVERY_SERVER_MODE_KEY = "spring.cloud.nacos.discovery.server-mode"; + + private static final String NACOS_SERVER_MODE_VALUE = "EDAS"; @Autowired(required = false) private AliCloudEdasSdk aliCloudEdasSdk; @@ -106,10 +108,14 @@ public class StatisticsTaskStarter implements InitializingBean { if (acmContextBootstrapConfiguration != null && acmEnableEdas) { components.add("SC-ACM"); } - if (NACOS_CONFIG_SERVER_MODE_VALUE + if (NACOS_SERVER_MODE_VALUE .equals(System.getProperty(NACOS_CONFIG_SERVER_MODE_KEY))) { components.add("SC-NACOS-CONFIG"); } + if (NACOS_SERVER_MODE_VALUE + .equals(System.getProperty(NACOS_DISCOVERY_SERVER_MODE_KEY))) { + components.add("SC-NACOS-DISCOVERY"); + } return components; } diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java new file mode 100644 index 000000000..74ac28bcb --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2018 the original author or authors. + * + * 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 org.springframework.cloud.alibaba.nacos; + +/** + * @author xiaolongzuo + */ +public class NacosDiscoveryAutoConfiguration { +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java index 393980015..ce4253503 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java @@ -16,43 +16,46 @@ package org.springframework.cloud.alicloud.context.nacos; -import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + import org.junit.BeforeClass; import org.junit.Test; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication; import org.springframework.cloud.alicloud.utils.ChangeOrderUtils; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; +import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; /** * @author xiaolongzuo */ -@PrepareForTest({EdasChangeOrderConfigurationFactory.class, - NacosConfigParameterInitListener.class, AliCloudAnsInitializer.class}) -public class NacosDiscoveryParameterInitListenerTests extends BaseAliCloudSpringApplication { +@PrepareForTest({ EdasChangeOrderConfigurationFactory.class, + NacosDiscoveryParameterInitListener.class, AliCloudAnsInitializer.class }) +public class NacosDiscoveryParameterInitListenerTests + extends BaseAliCloudSpringApplication { - @BeforeClass - public static void setUp() { - ChangeOrderUtils.mockChangeOrder(); - System.getProperties().setProperty("webContext", "/vipserver"); - System.getProperties().setProperty("serverPort", "80"); - } + @BeforeClass + public static void setUp() { + ChangeOrderUtils.mockChangeOrder(); + } - @Test - public void testNacosParameterInitListener() { - assertThat(System.getProperty("spring.cloud.nacos.config.server-addr")) - .isEqualTo(""); - assertThat(System.getProperty("spring.cloud.nacos.config.endpoint")) - .isEqualTo("testDomain"); - assertThat(System.getProperty("spring.cloud.nacos.config.namespace")) - .isEqualTo("testTenantId"); - assertThat(System.getProperty("spring.cloud.nacos.config.access-key")) - .isEqualTo("testAK"); - assertThat(System.getProperty("spring.cloud.nacos.config.secret-key")) - .isEqualTo("testSK"); - assertThat(System.getProperties().getProperty("webContext")).isEqualTo("/vipserver"); - assertThat(System.getProperties().getProperty("serverPort")).isEqualTo("80"); - } + @Test + public void testNacosParameterInitListener() { + assertThat(System.getProperty("spring.cloud.nacos.discovery.server-mode")) + .isEqualTo("EDAS"); + assertThat(System.getProperty("spring.cloud.nacos.discovery.server-addr")) + .isEqualTo(""); + assertThat(System.getProperty("spring.cloud.nacos.discovery.endpoint")) + .isEqualTo("testDomain"); + assertThat(System.getProperty("spring.cloud.nacos.discovery.namespace")) + .isEqualTo("testTenantId"); + assertThat(System.getProperty("spring.cloud.nacos.discovery.access-key")) + .isEqualTo("testAK"); + assertThat(System.getProperty("spring.cloud.nacos.discovery.secret-key")) + .isEqualTo("testSK"); + assertThat(System.getProperties().getProperty("webContext")) + .isEqualTo("/vipserver"); + assertThat(System.getProperties().getProperty("serverPort")).isEqualTo("80"); + } }