- 第一步:安装nacos
- 第二步:运行服务端
- 第三步client 服务
分三步, 最大的坑是版本 版本 还是版本!依赖一定要用对版本
第一步:安装nacoshttps://github.com/alibaba/nacos/releases/tag/1.0.1 最后面的是版本
下载下来后 先导入 nacos-mysql.sql 到本地数据库 然后 配置 application 主要配置
spring.datasource.platform=mysql ### Count of DB: db.num=1 ### Connect URL of DB: db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?serverTimezone=GMT%2B8&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user=root db.password=root
然后在bin目录运行 (win10): ./startup.cmd -m standalone
访问 http://127.0.0.1:8848/nacos 默认账密 nacos / nacos
注意 mysql8 需要2.0的nacos 不然会报连不上数据库
pom 注意 springboot和 nacos版本依赖
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.3.RELEASE com.terry nacos_platform 0.0.1-SNAPSHOT nacos_platform nacos_platform 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery 2.2.3.RELEASE org.springframework.boot spring-boot-starter-test test spring-milestones Spring Milestones https://repo.spring.io/milestone spring-snapshots Spring Snapshots https://repo.spring.io/snapshot true spring-milestones Spring Milestones https://repo.spring.io/milestone spring-snapshots Spring Snapshots https://repo.spring.io/snapshot true org.springframework.boot spring-boot-maven-plugin
服务端 yml
server:
port: 8070
spring:
application:
name: nacos-provider
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # nacos服务地址
# 自定义参数
myName: nacos-server
java启动类
package com.cn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient //开启服务注册发现功能
public class nacosProviderApplication {
public static void main(String[] args) {
SpringApplication.run(nacosProviderApplication.class, args);
}
}
第三步client 服务
yml 配置
server:
port: 8071
spring:
application:
name: nacos-consumer
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
myName: nacosConsumer
pom
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.3.RELEASE com.terry customer 0.0.1-SNAPSHOT customer customer 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery 2.2.3.RELEASE org.springframework.cloud spring-cloud-starter-openfeign 2.2.3.RELEASE org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
客户服务启动类
package com.terry.customer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class CustomerApplication {
public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class, args);
}
}



