“Spring Boot @ConfigurationProperties 配置绑定”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
(建立内容为“https://www.bilibili.com/video/BV19K4y1L7MT/?p=12”的新页面)
 
第1行: 第1行:
 
https://www.bilibili.com/video/BV19K4y1L7MT/?p=12
 
https://www.bilibili.com/video/BV19K4y1L7MT/?p=12
 +
 +
=== 旧的 properties 文件参数读取封装到 Java Bean ===
 +
<syntaxhighlight lang="java">
 +
public class getProperties {
 +
 +
    public static void main(String[] args) throws IOException {
 +
 +
        Properties pps = new Properties();
 +
        pps.load(new FileInputStream("a.properties"));
 +
        Enumeration<?> enumeration = pps.propertyNames(); //得到配置文件的名字
 +
        while (enumeration.hasMoreElements()) {
 +
            String strKey = (String) enumeration.nextElement();
 +
            String strValue = pps.getProperty(strKey);
 +
            System.out.println(strKey + "=" + strValue);
 +
            /**
 +
            * 封装到 Java Bean
 +
            * ……
 +
            */
 +
 +
        }
 +
 +
    }
 +
 +
}
 +
</syntaxhighlight>

2023年2月13日 (一) 05:42的版本

https://www.bilibili.com/video/BV19K4y1L7MT/?p=12

旧的 properties 文件参数读取封装到 Java Bean

public class getProperties {

    public static void main(String[] args) throws IOException {

        Properties pps = new Properties();
        pps.load(new FileInputStream("a.properties"));
        Enumeration<?> enumeration = pps.propertyNames(); //得到配置文件的名字
        while (enumeration.hasMoreElements()) {
            String strKey = (String) enumeration.nextElement();
            String strValue = pps.getProperty(strKey);
            System.out.println(strKey + "=" + strValue);
            /**
             * 封装到 Java Bean
             * ……
             */

        }

    }

}