From feeb171cff8a4c3867b327bcade3dc32f5b76b00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?=
<2291200076@qq.com>
Date: Sat, 5 Nov 2022 22:06:48 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5Nacos=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=B8=8E=E5=8F=91=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 34 ++++++++++++++++---
Solutions.md | 8 +++++
backend/microservice-gateway/pom.xml | 11 ++++++
.../main/java/com/cxyxiaomo/epp/Gateway.java | 2 ++
.../src/main/resources/application.yml | 3 ++
.../microservice-provider-test-8011/pom.xml | 24 +++++++++++++
.../java/com/cxyxiaomo/epp/TestProvider.java | 2 ++
.../src/main/resources/application.yml | 4 +++
backend/pom.xml | 32 +++++++++++++++++
9 files changed, 115 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 7c7c3de..f83e2de 100644
--- a/README.md
+++ b/README.md
@@ -104,11 +104,11 @@
项目开发环境:Ubuntu Desktop 22.04 LTS、OpenJDK 11、MySQL 8.0.12
-| 板块 | 技术栈 | 开发工具 | 备注 |
-| ------ | --------------------------------------------------------- | ------------- | ---- |
-| 前端 | Vue 3(JavaScript框架)、Element Plus(UI组件库) | VS Code | 暂定 |
-| 后端 | Java 11(开发语言)、SpringCloud(微服务)、Redis(缓存) | Intellij IDEA | |
-| 数据库 | MySQL(数据存储) | Navicat | |
+| 板块 | 技术栈 | 开发工具 | 备注 |
+| ------ | ------------------------------------------------------------ | ------------- | ---- |
+| 前端 | Vue 3(JavaScript框架)、Element Plus(UI组件库) | VS Code | 暂定 |
+| 后端 | Java 11(开发语言)、SpringCloud(微服务)、nacos-server-2.1.2(服务注册与发现)、Redis(缓存) | Intellij IDEA | |
+| 数据库 | MySQL(数据存储) | Navicat | |
@@ -172,6 +172,24 @@
### 后端
+#### 启动nacos
+
+Nacos下载地址:https://github.com/alibaba/nacos/releases/tag/2.1.2
+
+> standalone代表着单机模式运行,非集群模式
+>
+
+```bash
+cd nacos/bin
+# Windows
+startup.cmd -m standalone
+# Linux/Unix/Mac
+# sh startup.sh -m standalone
+# bash startup.sh -m standalone
+```
+
+Nacos后台默认用户名密码都是:**nacos**
+
### 前端
@@ -269,6 +287,12 @@ https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.5
MVN REPOSITORY:https://mvnrepository.com/
+#### Nacos
+
+Quick Start:https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html
+
+
+
### 前端
#### Element Plus
diff --git a/Solutions.md b/Solutions.md
index 8d0cb53..cdcd0a1 100644
--- a/Solutions.md
+++ b/Solutions.md
@@ -1,5 +1,13 @@
# 遇到的问题及对应的解决方案
+### 2022.11
+
+#### 2022.11.05 nacos启动报错Fail to init node, please see the logs to find the reason.
+
+Nacos启动程序路径不能有中文名
+
+
+
### 2022.10
#### 2022.10.22 CRLF换行替换为LF
diff --git a/backend/microservice-gateway/pom.xml b/backend/microservice-gateway/pom.xml
index 296aaa7..33b6cff 100644
--- a/backend/microservice-gateway/pom.xml
+++ b/backend/microservice-gateway/pom.xml
@@ -31,6 +31,17 @@
org.springframework.cloud
spring-cloud-starter-loadbalancer
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+ snakeyaml
+ org.yaml
+
+
+
ch.qos.logback
diff --git a/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java b/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
index 6157933..61bb138 100644
--- a/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
+++ b/backend/microservice-gateway/src/main/java/com/cxyxiaomo/epp/Gateway.java
@@ -2,8 +2,10 @@ package com.cxyxiaomo.epp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
+@EnableDiscoveryClient
public class Gateway {
public static void main(String[] args) {
SpringApplication.run(Gateway.class, args);
diff --git a/backend/microservice-gateway/src/main/resources/application.yml b/backend/microservice-gateway/src/main/resources/application.yml
index dc1d61d..b7f4f95 100644
--- a/backend/microservice-gateway/src/main/resources/application.yml
+++ b/backend/microservice-gateway/src/main/resources/application.yml
@@ -6,6 +6,9 @@ spring:
application:
name: microservice-gateway
cloud:
+ nacos:
+ discovery:
+ server-addr: 127.0.0.1:8848
gateway:
discovery:
locator:
diff --git a/backend/microservice-provider-test-8011/pom.xml b/backend/microservice-provider-test-8011/pom.xml
index 065b99f..87550d6 100644
--- a/backend/microservice-provider-test-8011/pom.xml
+++ b/backend/microservice-provider-test-8011/pom.xml
@@ -27,6 +27,30 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+ jackson-core
+ com.fasterxml.jackson.core
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+
ch.qos.logback
diff --git a/backend/microservice-provider-test-8011/src/main/java/com/cxyxiaomo/epp/TestProvider.java b/backend/microservice-provider-test-8011/src/main/java/com/cxyxiaomo/epp/TestProvider.java
index 8b1b4d9..3609b00 100644
--- a/backend/microservice-provider-test-8011/src/main/java/com/cxyxiaomo/epp/TestProvider.java
+++ b/backend/microservice-provider-test-8011/src/main/java/com/cxyxiaomo/epp/TestProvider.java
@@ -2,10 +2,12 @@ package com.cxyxiaomo.epp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
// 启动类
@SpringBootApplication
+@EnableDiscoveryClient
public class TestProvider {
public static void main(String[] args) {
SpringApplication.run(TestProvider.class, args);
diff --git a/backend/microservice-provider-test-8011/src/main/resources/application.yml b/backend/microservice-provider-test-8011/src/main/resources/application.yml
index 9f8141c..a280a1f 100644
--- a/backend/microservice-provider-test-8011/src/main/resources/application.yml
+++ b/backend/microservice-provider-test-8011/src/main/resources/application.yml
@@ -5,3 +5,7 @@ server:
spring:
application:
name: microservice-provider-test
+ cloud:
+ nacos:
+ discovery:
+ server-addr: 127.0.0.1:8848
diff --git a/backend/pom.xml b/backend/pom.xml
index 2cfc762..fb8fd68 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -32,6 +32,7 @@
8.0.30
1.2.8
+ 2.13.4
@@ -77,6 +78,20 @@
2.6.4
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+ 2021.1
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+ 2021.1
+
+
@@ -98,6 +113,23 @@
2.2.2
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ ${jackson.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ ${jackson.version}
+
+