Spring Cloud Alibaba(四):Nacos服務註冊與發現

微服務的起點就是服務註冊與發現,Spring Cloud Alibaba系列將使用Nacos作爲服務註冊與發現。

本節主要以nacos-server 1.4.1版本進行演示。

1 服務端

1.1 下載 nacos-server

https://download.csdn.net/download/qq_28336351/14936184

1.2 啓動服務

以Mac爲例,演示。

進入到 nacos/bin 目錄。

啓動命令:

sh startup.sh -m standalone

1.3 管理平臺

地址:http://localhost:8848/nacos

默認賬號:nacos

默認密碼:nacos

1.4 停止服務

以Mac爲例,演示。

進入到 nacos/bin 目錄。

啓動命令:

sh shutdown.sh

1.5 界面截圖

2 客戶端

2.1 依賴

<!-- nacos 服務註冊 -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

2.2 自動配置

/*
 * 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 com.fengwenyi.demouserservicecore.config;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;

/**
 * @author <a href="mailto:[email protected]">theonefx</a>
 */
@EnableDiscoveryClient
@Configuration
public class NacosDiscoveryConfiguration {
}

2.3 配置

spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.nacos.discovery.group=springcloud-alibaba-demo

2.4 界面截圖

3 資料

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章