【发布时间】:2019-06-13 11:35:15
【问题描述】:
在我的 Spring 项目中,我广泛使用了来自 vavr 库的集合。有时我需要注入 bean 的集合。据我所知,Spring 只能从 JDK 注入集合,例如List、Set、Map等有没有办法注入vavr集合?我想做这样的事情:
@Component
class NameResolver {
@Autowired
io.vavr.collection.List<NameMatcher> matchers; // how to make it work?
}
【问题讨论】:
-
是的,您可以自动装配此集合。但它应该在 Maven 依赖项列表中。
-
有什么奇怪的?我在类路径上有 vavr 库。
-
然后你可以将你的 jar 放在 Nexus 存储库中,你可以在 maven 中添加
-
我确实有这种依赖。我从 Maven Central mvnrepository.com/artifact/io.vavr/vavr/0.10.0 获取它
-
只要有该类型的列表作为可用的 bean,Spring 就会注入它。它不会自动注入该类型的 bean,它只会对 JDK 集合执行此操作。一种解决方法是注入普通集合,并在需要时将其包装在 vavr 中。
标签: java spring collections autowired vavr