您的位置:首页 > 编程语言 > Java开发

spring boot的 yml和properties的对比

2020-08-10 14:56 190 查看

转载自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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: