Instance<HttpAmClientTransport> clienttrnsportI = instance.select(HttpAmClientTransport.class);
HttpAmClientTransport clienttrnsport = clienttrnsportI.get();
其中HttpAmClientTransport.class是注入bean的本地接口 但如果我想在实例上调用iterator
Iterator<AmClientTransport> aaa = instance.iterator();
比这导致递归工厂类创建(执行@Produces方法)
Brian Blonski在这里讨论了答案
Java CDI: Dynamically selecting an implementation based on qualifier?
但在我的情况下,当我获得迭代器时出现递归,而不是通过.next()获取bean实例
我也需要你的建议。事实上,我有几个运输豆有自己的本地接口和几个客户端bean,我必须注入特定的传输。客户端(rest soap或db)和传输限定符(安全与否)的类型将在配置文件中给出,并且可能会更改。我认为我可以在枚举变量中使用必要的映射硬编码注释中的一些客户端配置约束,这将包含传输接口类。 这些接口(每个客户端bean一个)将由传输bean实现(并且可能是某些客户端实现了适合每个客户端的所有接口),但这是一个问题。 如何过滤掉在producer方法中实现特定于客户端的接口的所有传输bean 如果我改变
Instance<HttpAmClientTransport> clienttrnsport = instance.select(HttpAmClientTransport.class);
到
Instance<RestfulAmClientTransport> clienttrnsport = instance.select(RestfulAmClientTransport.class);
我有isUnsatisfied()属性true值(空实例) 但如果我改变那些
Instance<AmClientTransport> amtranses = instance.select(AmClientTransport.class);
比所有检查都是false,但get()方法导致整个生产者类的递归创建 我知道我遗漏了一些遗传但是什么呢?
我很感激你能给我的任何建议。
代码部分
restfullclient bean
public class RESTfulAmClientBean
extends BaseAmClient<RESTfulAmClientBean>
implements RESTfulAmClient , Serializable{
@Inject
private Logger logger;
private static final long serialVersionUID = 1L;
private AmClientTransport trns;
//private AmClientRequestBuilder rb;
//private AmClientSerializer serializer;
private AmObjectApiSettingsManager amCliSettMgr;
@Inject
@AmClientTransportProducer
private AmClientTransport restfulAmClientTransport;
生产者bean
@Local
public class AmClientTransportProducerImpl {
@Inject
private Logger logger;
@Inject
@Any
private Instance<AmClientTransport> trnsInst;
public AmClientTransportProducerImpl() {
}
@PostConstruct
private void initAmClientTransportProducerImpl(){
logger.debug("создание экземпляря класса AmClientTransportProducerImpl");
}
@AmClientTransportProducer
@Produces
public AmClientTransport getAmClientTransport(@Any Instance<AmClientTransport> instance , InjectionPoint ip){
logger.debug("запуск метода getAmClientTransport");
logger.debug("isAmbig:" + instance.isAmbiguous() + " isUnSatt" + instance.isUnsatisfied());
Instance<HttpAmClientTransport> clienttrnsport = instance.select(HttpAmClientTransport.class);
boolean isAmbig = clienttrnsport.isAmbiguous();
boolean isUnsat = clienttrnsport.isUnsatisfied();
//Iterator<AmClientTransport> aaa = instance.iterator();
// Here i have got recursion
//AmClientTransport trns2 = aaa.next();
HttpAmClientTransport trns = clienttrnsport.get();
Instance<AmClientTransport> restfultranses = instance.select(AmClientTransport.class);
isAmbig = restfultranses.isAmbiguous();
isUnsat = restfultranses.isUnsatisfied();
Iterator<AmClientTransport> it = restfultranses.iterator();
// Here i have got recursion too
if (
(!restfultranses.isUnsatisfied())
){
}
return null;
}
AmClientTransport界面只是界面
public interface AmClientTransport {}
扩展AmClientTransport的客户端特定传输接口
public interface RestfulAmClientTransport extends AmClientTransport {
public void execute();
}
本地特定传输Bean接口
@Local
public interface HttpAmClientTransport extends RestfulAmClientTransport{}
特定的传输Bean实现
@Stateless(mappedName = "HttpAmClientTransport")
@Local(HttpAmClientTransport.class)
@Default
public class HttpAmClientTransportImpl implements HttpAmClientTransport {
public HttpAmClientTransportImpl() {}
@Override
public void execute() {}
}