Nacos服务注册和配置中心

Nacos服务注册和配置中心

简介

Nacos 前两个字母分别是NamingConfiguration的前两个字母,最后s为Service

官网地址:https://nacos.io/zh-cn/

GitHub:https://github.com/alibaba/nacos

Spring Cloud Alibaba Reference Documentation

Nacos:Eureka+Confg+Bus

Nacos 的关键特性包括:

  • 服务发现和服务健康监测
  • 动态配置服务
  • 动态 DNS 服务
  • 服务及其元数据管理

安装

所有版本地址:https://github.com/alibaba/nacos/releases

nacos-server-1.4.4.zip下载链接https://github.com/alibaba/nacos/releases/download/1.4.4/nacos-server-1.4.4.zip

下载解压,进入/bin,命令行输入。

startup -m standalone

访问界面http://127.0.0.1:8848/nacos/

一般pom文件

<dependencies>
    
    <dependency>
        <groupId>com.alibaba.cloudgroupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
    dependency>
    
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
    dependency>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-actuatorartifactId>
    dependency>
    
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-devtoolsartifactId>
        <scope>runtimescope>
        <optional>trueoptional>
    dependency>
    <dependency>
        <groupId>org.projectlombokgroupId>
        <artifactId>lombokartifactId>
        <optional>trueoptional>
    dependency>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-testartifactId>
        <scope>testscope>
    dependency>
dependencies>

测试Demo

  • application.yml
server:
  port: 9001

spring:
  application:
    name: nacos-payment-provider
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848 #配置Nacos地址

management:
  endpoints:
    web:
      exposure:
        include: '*'

Main.java

@EnableDiscoveryClient
@SpringBootApplication
public class PaymentMain9001
{
    public static void main(String[] args) {
            SpringApplication.run(PaymentMain9001.class, args);
    }
}

你可能感兴趣的:(后端,java,spring,cloud,spring,cloud,java)