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

前端 未结 16 1362
陌清茗
陌清茗 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:24

    My preferred way (for strings, in particular), is the following one:

    admin.user={'Doe, John','Headroom, Max','Mouse, Micky'}
    

    and use

    @Value("#{${admin.user}}")
    private List userList;
    

    In this way, you can include also commas in your parameter. It works also for Sets.

提交回复
热议问题