【发布时间】:2014-06-12 04:35:10
【问题描述】:
我有一些资源,但我不能迭代它并将它们全部绑定, 我必须使用密钥来请求资源。所以,我必须动态注入。
我定义了一个注释
@Target({ METHOD, CONSTRUCTOR, FIELD })
@Retention(RUNTIME)
@Documented
@BindingAnnotation
public @interface Res
{
String value();// the key of the resource
}
这样使用
public class Test
{
@Inject
@Res("author.name")
String name;
@Inject
@Res("author.age")
int age;
@Inject
@Res("author.blog")
Uri blog;
}
我必须处理@Res 注释的注入,我需要知道
注入字段和注释。
这在Guice 中是否可行?如何实现?即使有 spi ?
【问题讨论】:
标签: java inversion-of-control guice inject