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

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

    if using property placeholders then ser1702544 example would become

    @Value("#{myConfigProperties['myproperty'].trim().replaceAll(\"\\s*(?=,)|(?<=,)\\s*\", \"\").split(',')}") 
    

    With placeholder xml:

       
        
        $myConfigProperties{
        
    
    
         
             
                    classpath:myprops.properties
             
         
     
    

提交回复
热议问题