【发布时间】:2015-05-07 13:55:20
【问题描述】:
有没有办法在 CDI 中做类似的事情:
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface ServerConfiguration {
@Nonbinding String url() default "http://localhost:8080";
@Nonbinding String username() default "";
@Nonbinding String password() default "";
}
然后定义第二个类似的注解:
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@ServerConfiguration(username = "abc123")
public @interface MainServer {
}
有可能为服务器配置设置一个生产者,但有可能指定不同的默认配置?
服务器配置只是一个例子,但它说明了我的意思。基本上是一个通用限定符,如果需要可以专门化。
谢谢!
【问题讨论】: