From 42026bcb95b282403cea4e9ae25f8091e88675f5 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 5 Feb 2019 22:25:11 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E9=9B=86=E6=88=90nacos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-core-cloud/pom.xml | 10 ++--- .../core/launch/BladeApplication.java | 11 +++--- .../{consul => constant}/ConsulConstant.java | 2 +- .../core/launch/constant/NacosConstant.java | 39 +++++++++++++++++++ pom.xml | 1 + 5 files changed, 50 insertions(+), 13 deletions(-) rename blade-core-launch/src/main/java/org/springblade/core/launch/{consul => constant}/ConsulConstant.java (95%) create mode 100644 blade-core-launch/src/main/java/org/springblade/core/launch/constant/NacosConstant.java diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index 650ee48..e96cbb5 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -57,16 +57,14 @@ org.springframework.cloud - spring-cloud-starter-config + spring-cloud-starter-alibaba-nacos-discovery + ${nacos.version} org.springframework.cloud - spring-cloud-starter-consul-discovery + spring-cloud-starter-alibaba-nacos-config + ${nacos.version} - diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/BladeApplication.java b/blade-core-launch/src/main/java/org/springblade/core/launch/BladeApplication.java index 84b1c31..2ac26e0 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/BladeApplication.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/BladeApplication.java @@ -16,7 +16,7 @@ package org.springblade.core.launch; import org.springblade.core.launch.constant.AppConstant; -import org.springblade.core.launch.consul.ConsulConstant; +import org.springblade.core.launch.constant.NacosConstant; import org.springblade.core.launch.service.LauncherService; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ConfigurableApplicationContext; @@ -92,11 +92,10 @@ public class BladeApplication { props.setProperty("blade.is-local", String.valueOf(isLocalDev())); props.setProperty("blade.dev-mode", profile.equals(AppConstant.PROD_CODE) ? "false" : "true"); props.setProperty("blade.service.version", AppConstant.APPLICATION_VERSION); - props.setProperty("spring.cloud.consul.host", ConsulConstant.CONSUL_HOST); - props.setProperty("spring.cloud.consul.port", ConsulConstant.CONSUL_PORT); - props.setProperty("spring.cloud.consul.config.format", ConsulConstant.CONSUL_CONFIG_FORMAT); - props.setProperty("spring.cloud.consul.watch.delay", ConsulConstant.CONSUL_WATCH_DELAY); - props.setProperty("spring.cloud.consul.watch.enabled", ConsulConstant.CONSUL_WATCH_ENABLED); + props.setProperty("spring.cloud.nacos.discovery.server-addr", NacosConstant.NACOS_ADDR); + props.setProperty("spring.cloud.nacos.config.server-addr", NacosConstant.NACOS_ADDR); + props.setProperty("spring.cloud.nacos.config.prefix", NacosConstant.NACOS_CONFIG_PREFIX); + props.setProperty("spring.cloud.nacos.config.file-extension", NacosConstant.NACOS_CONFIG_FORMAT); // 加载自定义组件 ServiceLoader loader = ServiceLoader.load(LauncherService.class); loader.forEach(launcherService -> launcherService.launcher(builder, appName, profile)); diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/consul/ConsulConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/ConsulConstant.java similarity index 95% rename from blade-core-launch/src/main/java/org/springblade/core/launch/consul/ConsulConstant.java rename to blade-core-launch/src/main/java/org/springblade/core/launch/constant/ConsulConstant.java index 436443d..8a4a6fe 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/consul/ConsulConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/ConsulConstant.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.launch.consul; +package org.springblade.core.launch.constant; /** * Consul常量. diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/NacosConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/NacosConstant.java new file mode 100644 index 0000000..d7e2ea6 --- /dev/null +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/NacosConstant.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * 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.springblade.core.launch.constant; + +/** + * Nacos常量. + * + * @author Chill + */ +public interface NacosConstant { + + /** + * nacos 地址 + */ + String NACOS_ADDR = "127.0.0.1:8848"; + + /** + * nacos 配置前缀 + */ + String NACOS_CONFIG_PREFIX = "blade"; + + /** + * nacos 配置文件类型 + */ + String NACOS_CONFIG_FORMAT = "yaml"; +} diff --git a/pom.xml b/pom.xml index 8a7e5a2..8e4aaa9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ 3.4.2 2.0.2 1.0.1 + 0.2.1.RELEASE 2.0.7.RELEASE Finchley.SR2