Reading a List from properties file and load with spring annotation @Value

前端 未结 16 1503
陌清茗
陌清茗 2020-11-22 14:01

I want to have a list of values in a .properties file, ie:

my.list.of.strings=ABC,CDE,EFG

And to load it in my class directly, ie:

16条回答
  •  一个人的身影
    2020-11-22 14:19

    Using Spring EL:

    @Value("#{'${my.list.of.strings}'.split(',')}") 
    private List myList;
    

    Assuming your properties file is loaded correctly with the following:

    my.list.of.strings=ABC,CDE,EFG
    

提交回复
热议问题