惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 飞翔在天

【转载】技术方案设计的方法论及案例分享—如何体现技术深度 云原生 性能调优 团队管理 技术管理 【生产案例】日登录用户、月登录用户统计、聚合统计 【生产案例】点赞数、排行榜、未读消息数(含B站方案) - 飞翔在天 【JVM】类加载器&双亲委派 【架构】单元化架构 如何写好代码 【缓存】基本理论 Lambda架构和Kappa架构 【生产案例】 【架构-案例】聊天系统 【Spring】整体 【JVM】 【Spring-WebFlux】响应式 AI ServiceComb
【配置项读取】
飞翔在天 · 2025-08-01 · via 博客园 - 飞翔在天

Archaius实际上是对Apache Common Configuration Library的一个封装和扩展,提供了一组基于Java的配置API,主要的特性包括:

  • 配置可动态调整:动态、类型属性,在修改配置后,不需要重启应用服务。其核心思想就是轮询配置源,每一次迭代,检测配置是否更改,有更改重新更新配置。
  • 配置支持类型(Int, Long, Boolean等)。
  • 高性能和线程安全:高吞吐量和线程安全的配置操作
  • 提供一个拉(pulling)配置的框架,可以从配置源动态拉取变更的配置。(一个轮询框架,允许用户获取对配置源的属性更改)
  • 支持回调(callback)机制,在配置变更时自动调用。
  • 支持JMX MBean,可以通过JConsole查看配置和修改配置。

获取参数的办法:DynamicPropertyFactory,获取配置项的DynamicProperty wrapper。

DynamicPropertyFactory.getInstance().getStringProperty
<dependency>
    <groupId>com.netflix.archaius</groupId>
    <artifactId>archaius-core</artifactId>
    <version>0.7.7</version>
</dependency>

Archaius Core 本身并没有默认的配置文件名称,它是一个动态配置管理工具,支持从多种配置源(如 Properties 文件、Consul、DynamoDB 等)读取配置。默认情况下,它不会自动读取特定的配置文件,而是需要通过配置来指定要使用的配置源。

  • 如果你使用 Archaius Core,默认情况下它不会自动加载任何配置文件或配置源。
  • 你需要通过配置(如 application.properties 或 bootstrap.properties)来指定要使用的配置源及其路径。

如何指定配置文件

如果你希望 Archaius Core 读取特定的配置文件(如 config.properties),你需要在配置文件中指定:

# 指定 Properties 文件作为配置源
archaius.sources[0].type=properties
archaius.sources[0].path=classpath:config.properties

这样,Archaius Core 会从类路径下读取 config.properties 文件。

与 Spring Boot 集成时的默认行为:如果你在 Spring Boot 项目中使用 Archaius Core,默认情况下,Spring Boot 会加载 application.properties 或 application.yml 文件。

  • 如果你使用 Spring Boot,可以将配置文件放在 src/main/resources 目录中,并通过 application.properties 指定配置源。