草庐IT

YourInterface

全部标签

java - 如何使用 Guice 获取接口(interface)的所有实现者/子类?

使用Spring,您可以定义一个数组属性,并让Spring注入(inject)从给定类型派生的每个(@Component)类之一。在Guice中有对应的吗?或者添加此行为的扩展点? 最佳答案 这看起来像是Guice的用例MultiBinder.你可以有这样的东西:interfaceYourInterface{...}classAimplementsYourInterface{...}classBimplementsYourInterface{...}classYourModuleextendsAbstractModule{@Over