首页 > 其他 > 详细

@ConfigurationProperties实现自定义配置绑定

时间:2021-09-01 17:04:51      阅读:8      评论:0      收藏:0      [点我收藏+]

@ConfigurationProperties使用

技术分享图片
@ConfigurationProperties(

        prefix = "hello.properties"

)

public class MyProperties {


    private String myKey;

    private List<String> stringList;

    private Duration duration;


    public String getMyKey() {

        return myKey;

    }


    public void setMyKey(String myKey) {

        this.myKey = myKey;

    }


    public List<String> getStringList() {

        return stringList;

    }


    public void setStringList(List<String> stringList) {

        this.stringList = stringList;

    }


    public Duration getDuration() {

        return duration;

    }


    public void setDuration(Duration duration) {

        this.duration = duration;

    }


    @Override

    public String toString() {

        return "MyProperties{" +

                "myKey=‘" + myKey + ‘\‘‘ +

                ", stringList=" + stringList +

                ", duration=" + duration +

                ‘}‘;

    }

}
View Code

prefix属性是配置文件里的前缀,即配置文件中以前缀 + 变量名的形式配置一条记录,来对应类中的一个变量,如下:

hello.properties.myKey=hello

hello.properties.duration=20s

hello.properties.string-list[0]=Acelin

hello.properties.string-list[1]=nice

@ConfigurationProperties特点

hello.properties.myKey=hello

hello.properties.mykey=hello

hello.properties.my-key=hello

hello.properties.my_key=hello

hello.properties.MY_KEY=hello

hello.properties.MY-KEY=hello

https://www.cnblogs.com/acelin/p/15167266.html

 

@ConfigurationProperties实现自定义配置绑定

原文:https://www.cnblogs.com/luweiweicode/p/15203234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!