1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

引入Nacos服务注册与发现

This commit is contained in:
程序员小墨 2022-11-05 22:06:48 +08:00
parent ef6467882d
commit feeb171cff
9 changed files with 115 additions and 5 deletions

View File

@ -104,11 +104,11 @@
项目开发环境Ubuntu Desktop 22.04 LTS、OpenJDK 11、MySQL 8.0.12 项目开发环境Ubuntu Desktop 22.04 LTS、OpenJDK 11、MySQL 8.0.12
| 板块 | 技术栈 | 开发工具 | 备注 | | 板块 | 技术栈 | 开发工具 | 备注 |
| ------ | --------------------------------------------------------- | ------------- | ---- | | ------ | ------------------------------------------------------------ | ------------- | ---- |
| 前端 | Vue 3JavaScript框架、Element PlusUI组件库 | VS Code | 暂定 | | 前端 | Vue 3JavaScript框架、Element PlusUI组件库 | VS Code | 暂定 |
| 后端 | Java 11开发语言、SpringCloud微服务、Redis缓存 | Intellij IDEA | | | 后端 | Java 11开发语言、SpringCloud微服务nacos-server-2.1.2(服务注册与发现)、Redis缓存 | Intellij IDEA | |
| 数据库 | MySQL数据存储 | Navicat | | | 数据库 | 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 REPOSITORYhttps://mvnrepository.com/ MVN REPOSITORYhttps://mvnrepository.com/
#### Nacos
Quick Starthttps://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html
### 前端 ### 前端
#### Element Plus #### Element Plus

View File

@ -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
#### 2022.10.22 CRLF换行替换为LF #### 2022.10.22 CRLF换行替换为LF

View File

@ -31,6 +31,17 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId> <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency> </dependency>
<!-- Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- logback --> <!-- logback -->
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>

View File

@ -2,8 +2,10 @@ package com.cxyxiaomo.epp;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient
public class Gateway { public class Gateway {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Gateway.class, args); SpringApplication.run(Gateway.class, args);

View File

@ -6,6 +6,9 @@ spring:
application: application:
name: microservice-gateway name: microservice-gateway
cloud: cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
gateway: gateway:
discovery: discovery:
locator: locator:

View File

@ -27,6 +27,30 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<!-- logback --> <!-- logback -->
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>

View File

@ -2,10 +2,12 @@ package com.cxyxiaomo.epp;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
// 启动类 // 启动类
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient
public class TestProvider { public class TestProvider {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TestProvider.class, args); SpringApplication.run(TestProvider.class, args);

View File

@ -5,3 +5,7 @@ server:
spring: spring:
application: application:
name: microservice-provider-test name: microservice-provider-test
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848

View File

@ -32,6 +32,7 @@
<mysql.version>8.0.30</mysql.version> <mysql.version>8.0.30</mysql.version>
<druid.version>1.2.8</druid.version> <druid.version>1.2.8</druid.version>
<!--<mybatis.spring.boot.version>2.2.2</mybatis.spring.boot.version>--> <!--<mybatis.spring.boot.version>2.2.2</mybatis.spring.boot.version>-->
<jackson.version>2.13.4</jackson.version>
</properties> </properties>
<!-- 子 module 继承之后,锁定版本 + 不用写groupId和version --> <!-- 子 module 继承之后,锁定版本 + 不用写groupId和version -->
@ -77,6 +78,20 @@
<version>2.6.4</version> <version>2.6.4</version>
</dependency> </dependency>
<!-- Nacos -->
<!-- 服务注册发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version>
</dependency>
<!-- 配置中心依赖管理 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2021.1</version>
</dependency>
<!-- Database --> <!-- Database -->
<!-- mysql --> <!-- mysql -->
<dependency> <dependency>
@ -98,6 +113,23 @@
<version>2.2.2</version> <version>2.2.2</version>
</dependency> </dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Log --> <!-- Log -->
<!-- log4j --> <!-- log4j -->
<dependency> <dependency>