當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Nacos 集群 Nginx MySql SpringBoot2.x 微服务_04
生活随笔
收集整理的這篇文章主要介紹了
Nacos 集群 Nginx MySql SpringBoot2.x 微服务_04
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
接上一篇:
Nacos 集群整合 Nginx 實現反向代理、負載均衡_03
文章目錄
- 一、配置規則
- 1. 域名登錄nacos
- 2. 測試驗證
- 二、SpringBoot2.x 微服務
- 2.1. 依賴引入
- 2.2. bootstrap.yaml配置
- 2.3. 測試類
- 三、測試驗證
- 3.1. 啟動項目
- 3.2. 驗證
一、配置規則
1. 域名登錄nacos
使用域名登錄nacos配置規則
| Data ID | nacos-config-prod.yaml | |
| Group | DEFAULT_GROUP | 默認,可以自定義 |
| 描述 | 簡述生產環境配置 | |
| 配置格式 | yaml | 文件擴展名選擇 |
| 配置內容 | nacosProd: Production environment configuration | 和配置yml文件格式語法一樣 |
2. 測試驗證
使用域名登錄nacos,并配置規則,分別登錄nacos應用查看配置是否同步
二、SpringBoot2.x 微服務
2.1. 依賴引入
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.2.RELEASE</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--服務注冊發現--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--配置管理--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency></dependencies><dependencyManagement><dependencies><!--spring-cloud-alibaba依賴版本控制--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.2.6.RELEASE</version><scope>import</scope><type>pom</type></dependency></dependencies></dependencyManagement>2.2. bootstrap.yaml配置
spring:cloud:nacos:server-addr: 192.168.159.102:8848,192.168.159.103:8848,192.168.159.104:8848 # nacos集群服務地址config:file-extension: yaml # 表示支持擴展的文件名application:name: nacos-config # 表示當前微服務需要向配置中心索要nacos-config的配置profiles:active: prod # 表示我需要向配置中心索要生產環境的配置server:port: 9000management:endpoint:endpoints:web:exposure:include: '*'2.3. 測試類
package com.gblfy.nacosconfig.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;@RestController @RefreshScope public class NaocsController {@Value("${nacosProd}")private String nacosProd;@GetMapping("/nacosProd")public String getNacosProd() {return nacosProd;} }三、測試驗證
3.1. 啟動項目
3.2. 驗證
http://localhost:9000/nacosProd
總結
以上是生活随笔為你收集整理的Nacos 集群 Nginx MySql SpringBoot2.x 微服务_04的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RuoYi-Vue 部署 Linux环境
- 下一篇: KAFKA 集成 SpringBoot2