Springboot集成Apollo

本文详细介绍如何在SpringBoot项目中集成Apollo配置中心,包括本地部署Apollo、项目配置添加、Maven依赖引入及配置信息注入步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、有Apollo配置中心提供配置

windows本地部署apollo: https://blog.youkuaiyun.com/qq_35556233/article/details/104626366

二、Springboot项目接入apollo

1、在apollo中添加项目配置

其中appid在springboot接入apollo中需要配置

新建之后就和提供的例子一样

可以在其中添加发布你想要增加的配置信息

2、springboot接入必需配置如下配置:

app_id 你所创建的apollo配置项目的id

meta:你的apollo项目请求地址

Environment:dev、fat、uat、pro四种环境

放在application.yml文件中的配置

apollo:
  bootstrap:
    enabled: true

app:
  id: short_url

其中apollo.meta和Environment可以加在application.yml文件中也可以放在server.properties文件中

windows:C:\opt\settings\server.properties

linux: /opt/settings/server.properties

server.properties内容如下:

env=DEV
apollo.meta=http://127.0.0.1:8080/

3、maven中添加依赖

<dependency>
    <groupId>com.ctrip.framework.apollo</groupId>
    <artifactId>apollo-client</artifactId>
    <version>1.1.0</version>
</dependency>

4、注入配置信息

@EnableApolloConfig
@Value("${redisDatabase}")

当你在运行Armbian系统的设备上想要更换软件源(通常是为了加速下载或解决地区限制的问题),你可以按照下面的步骤操作: ### 更换Armbian系统默认源 #### 步骤一:备份原始文件 首先,你需要对现有的`sources.list`文件做一份副本。这可以帮助你在遇到问题的时候快速恢复。 ```bash sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` #### 步骤二:编辑 sources 文件 接下来就是实际修改的地方了,我们打开 `sources.list` 进行编辑: ```bash sudo nano /etc/apt/sources.list ``` #### 步骤三:更改镜像地址 将原有的内容替换为你所选择的新镜像服务器URL,例如阿里云、清华大学等提供的国内镜像站点链接。对于大部分用户来说,可以考虑使用如下的清华源配置作为参考模板之一(假设你正在使用的Armbian版本基于Debian Buster): ```plaintext deb https://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free ``` 注意:如果你使用的是其他分支或是非官方库,则需要相应调整上述路径。 #### 步骤四:更新包索引并测试新源 保存并关闭文本编辑器之后,通过执行以下命令来让新的设置生效,并检查是否能正常工作: ```bash sudo apt-get update && sudo apt-get upgrade -y ``` 如果一切顺利的话,那么你就成功地完成了更换Armbian软件源的操作!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值