application.yml中的配置
test:
testList1: item1, item2, item3, item4
testList2:
- item1
- item2
- item3
testList1使用逗号分隔,testList2使用 - 短线
单元测试:
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
@SpringBootTest
class

这篇博客介绍了如何在Java应用中读取yaml配置文件中的集合。文章指出,使用`environment`和`@Value`注解无法正确读取用短横线(-)分隔的集合,但可以通过创建对应的JavaBean来接收这些配置。同时提到,逗号分隔的集合配置既支持JavaBean方式,也支持`environment`和`@Value`注解读取。在测试代码中,使用了hutool库的CollectionUtil。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



