在java中propertiesconfiguration与Properties是一样的吗 - 爱问答

(爱问答)

在java中propertiesconfiguration与Properties是一样的吗

propertiesconfiguration这个类是在学习Applet是用到的,也想顺便问一下Applet过时了吗

1、PropertiesConfiguration很少见,查了一下是Tomcat的类,应该是加载配置文件的。而Properties是java原生的集合类,HashTable的子类(Map的一种)。


2、Applet是java早期的Web控件,现已废弃

发现有一点区别,我项目配置中并没有配置hello.msg ,当使用第一段代码时,启动后读取到msg为null,而第二段代码则会抛出异常。第二段代码有个好处,就是防止我们配置项遗漏,当遗漏时,启动程序肯定出错,这样避免了一些因为遗漏配置项导致的BUG.

第一段代码

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("hello")
public class HelloProperties {
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
第二段代码

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Hello2Properties {
    @Value("${hello.msg}")
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

 

相关标签:java

下一篇:AdobeFlashPlayer

上一篇:大数据现在很火,请问如果想学大数据,应该去哪里培训比较好?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?