当前位置: 首页 > news >正文

alibabacloud的简单使用,nacos配置中心+服务中心。作者直接给自己写的源码

文章目录

  • 依赖关键
  • 主要的程序
    • 启动文件
    • 配置文件bootstrap.yml
    • 依赖文件
    • nacos配置中心上的文件截图
  • 启动成功截图
  • 参考文档

依赖关键

  • SpringBoot版本和com.alibaba.cloud版本需要对应,不然会程序会启动失败
  • 作者使用的版本
SpringBoot: 2.1.6.RELEASE
alibabacloud: 2.1.2.RELEASE

主要的程序

启动文件

package com.example.user;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;/*** @author ljj* @date 2023/8/25 11:15* @desc*/
@SpringBootApplication
@EnableDiscoveryClient
public class UserApplication {public static void main(String[] args) {SpringApplication.run(UserApplication.class, args);}}

配置文件bootstrap.yml

server:port: 8080
spring:application:name: user-testnamespace: test_projectjackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT+8profiles:active: prodcloud:nacos:discovery:server-addr: localhost:8848username: nacospassword: nacos#只能填id,不能填 namespace的名字namespace: test_projectconfig:name: ${spring.application.name}-${spring.profiles.active}server-addr: localhost:8848username: nacospassword: nacos#只能填id,不能填 namespace的名字namespace: test_projectfile-extension: yml

依赖文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>test_project</artifactId><version>1.0-SNAPSHOT</version><packaging>pom</packaging><modules><module>user</module><module>order</module><module>product</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><version>2.1.2.RELEASE</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId><version>2.1.2.RELEASE</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies></project>

nacos配置中心上的文件截图

在这里插入图片描述
在这里插入图片描述

启动成功截图

在这里插入图片描述
在这里插入图片描述

参考文档

  • Spring cloud alibaba 版本对应关系及说明
http://www.lryc.cn/news/147409.html

相关文章:

  • Python爬虫:一个爬取豆瓣电影人像的小案例
  • STM32CubeMX配置STM32G0 Standby模式停止IWDG(HAL库开发)
  • 39.RESTful案例
  • Power Pivot 实现数据建模
  • Ansible自动化运维之playbooks剧本
  • Docker - Docker安装MySql并启动
  • SQL Server 2019导入txt数据
  • 科研 | Zotero导入无PDF的参考文献、书籍
  • 【Docker】docker入门之dockerfile编写
  • javaee之黑马乐优商城1
  • 滴滴前端一面面经(已挂)
  • 靠谱的适合上班族做的副业,这几种一定要试试!
  • VSCode连接服务器
  • Python爬虫网络安全:优劣势和适用范围分析
  • swift APP缓存
  • Linux中的dpkg指令(dpkg -l | grep XXX等)
  • import type {} from ‘module‘ 具体解释
  • 十年JAVA搬砖路——数据结构线性结构
  • Mybatis为什么需要预编译等一系列问题
  • 【JVM基础】JVM入门基础
  • 【SpringBoot】详细介绍Spring Boot中@Component
  • Redis执行lua脚本-Time函数-获取当前时间
  • 前端无需install快速调试npm包,Console-Import使用
  • 构建稳定的爬虫系统:如何选择合适的HTTP代理服务商
  • Python爬虫基础:使用Scrapy库初步探索
  • MacBookPro重装系统图文教程
  • Android 6.0长按电源键添加重启菜单
  • Python股票交易---均值回归
  • 机器人制作开源方案 | 桌面级机械臂--本体说明+驱动及控制
  • 有哪些前端调试和测试工具? - 易智编译EaseEditing