spring boot的 yml和properties的对比

本文对比了Spring Boot中application.yml和application.properties两种配置文件的使用。YAML格式因更简洁、易读而受到青睐,但properties文件在优先级处理上更直接。文章还介绍了如何在YAML中注入属性值。

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

转载自https://www.cnblogs.com/dyh-air/articles/9090882.html

总结:1、application.properties优先级高
2、application.yml写法看起来高大上简洁很多
3、application.properties可以直接用@Value获取值,yml需要如下


```java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource("classpath:ftpconfig.yml")
@ConfigurationProperties(prefix = "ftp")
public class FtpProperties {

    @Value("${ftplp}")
    public String ftplp;
[原文](https://www.cnblogs.com/dyh-air/articles/9090882.html)
[参考获取Value值的方法](https://www.cnblogs.com/dbright/p/11376078.html)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值