在我们的应用程序中,我们需要在GWT客户端和服务器之间共享域代码。因此,我们使用GWT代理和服务器端实体的通用接口。 @ thomas-broyer曾在这里描述过这种方法:https://stackoverflow.com/a/15852887/187241
异常堆栈跟踪:
ERROR com.google.web.bindery.requestfactory.server.SimpleRequestProcessor - Error while processing request
java.lang.UnsupportedOperationException: se.homework.hwbs.domain.shared.model.IAppointment
at com.google.web.bindery.autobean.shared.ValueCodex.getTypeOrDie(ValueCodex.java:388)
at com.google.web.bindery.autobean.shared.ValueCodex.decode(ValueCodex.java:312)
at com.google.web.bindery.requestfactory.shared.impl.EntityCodex.decode(EntityCodex.java:107)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor$3.visitReferenceProperty(SimpleRequestProcessor.java:633)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:370)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:162)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:97)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processOperationMessages(SimpleRequestProcessor.java:623)
共享代码:
public interface IAppointment {
IPlace getPlace();
}
public interface AppointmentProxy extends EntityProxy, IAppointment {
@Override
PlaceProxy getPlace();
}
public interface PlaceProxy extends EntityProxy, IPlace {
@Override
Long getId();
}
public interface IPlace extends IDatabaseEntity {
@Override
Long getId();
}
public interface IDatabaseEntity {
public Long getId();
}
如果我们正确地忽略了GWT代码,问题的原因来自ProxyAutoBean
:
for (Method method : beanType.getMethods()) {
if (BeanMethod.GET.matches(method)) {
toReturn.getters.add(method);
其中beanType
为AppointmentProxy.class
。 Java反射为这样的接口返回两种方法(仅在超级开发模式下发生......):
public **abstract** PlaceProxy AppointmentProxy.getPlace()
public **default** IPlace AppointmentProxy.getPlace()
第一个是GWT RequestFactory代码预期和接受,第二个不是......它导致java.lang.UnsupportedOperationException: IAppointment
异常。非常奇怪的事实是我们只在编译的GWT应用程序中才有这个问题。当我们使用超级开发模式从IDE启动应用程序时,未列出第二个default ...
方法,并且应用程序正常运行且没有错误。
环境:
您对如何修复或解决问题有任何想法吗?