我已經創建了擴展,警報管理器: 接口如何覆蓋掛毯AlertManager
public interface AlertManagerExt extends AlertManager {
void successCode(String messageCode, Object... args);
void infoCode(String messageCode, Object... args);
void warnCode(String messageCode, Object... args);
void errorCode(String messageCode, Object... args);
}
和實施
public class AlertManagerExtImpl extends AlertManagerImpl implements AlertManagerExt {
private final Messages messages;
public AlertManagerExtImpl(ApplicationStateManager asm, Request request, AjaxResponseRenderer ajaxResponseRenderer,
PerthreadManager perThreadManager, Messages messages) {
super(asm, request, ajaxResponseRenderer, perThreadManager);
this.messages = messages;
}
@Override
public void successCode(String messageCode, Object... args) {
success(getMessage(messageCode, args));
}
@Override
public void infoCode(String messageCode, Object... args) {
info(getMessage(messageCode, args));
}
@Override
public void warnCode(String messageCode, Object... args) {
warn(getMessage(messageCode, args));
}
@Override
public void errorCode(String messageCode, Object... args) {
error(getMessage(messageCode, args));
}
protected String getMessage(String code, Object... args) {
if (args.length > 0) {
return messages.format(code, args);
}
return messages.get(code);
}
}
當我試圖通過粘結劑結合它:
binder.bind(AlertManagerExt.class, AlertManagerExtImpl.class);
我得到異常:
java.lang.RuntimeException: Service interface org.apache.tapestry5.alerts.AlertManager is matched by 2 services: AlertManager, AlertManagerExtImpl. Automatic dependency resolution requires that exactly one service implement the interface.
at org.apache.tapestry5.ioc.internal.RegistryImpl.getServiceByTypeAlone(RegistryImpl.java:789)
at org.apache.tapestry5.ioc.internal.RegistryImpl.getServiceByTypeAndMarkers(RegistryImpl.java:797)
at org.apache.tapestry5.ioc.internal.RegistryImpl.getService(RegistryImpl.java:755)
我知道我可以複製並粘貼AlertManager中的所有方法,但不要擴展它。但可能有更好的辦法?
我需要的是從服務實現的源代碼很明顯。我對T5 IoC非常熟悉,我在我的問題中以stackoverflow發佈的原因是我的案例沒有在文檔中介紹。 – xl0e