我们正在尝试使用RequestFactory
现有的 Java 实体模型。我们的 Java 实体都实现了一个DomainObject
接口并公开了一个getObjectId()
方法(这个名称被选择为getId()
可能是模棱两可的,并且与正在建模的域中的域对象的实际ID 冲突。
该ServiceLayerDecorator
接口允许自定义 ID 和版本属性查找策略。
public class MyServiceLayerDecorator extends ServiceLayerDecorator {
@Override
public Object getId(Object object) {
DomainObject domainObject = (DomainObject) object;
return domainObject.getObjectId();
}
}
到现在为止还挺好。但是,尝试部署此解决方案会产生运行时错误。特别是RequestFactoryInterfaceValidator
抱怨:
[ERROR] There is no getId() method in type com.mycompany.server.MyEntity
然后稍后:
[ERROR] Type type com.mycompany.client.MyEntityProxy was previously marked as bad
[ERROR] The type com.mycompany.client.MyEntityProxy did not pass RequestFactory validation
[ERROR] Unexpected error
com.google.web.bindery.requestfactory.server.UnexpectedException: The type com.mycompany.client.MyEntityProxy did not pass RequestFactory validation
at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.die(ServiceLayerDecorator.java:212) ~[gwt-servlet.jar:na]
我的问题是 - 如果硬编码和的约定,为什么ServiceLayerDecorator
允许自定义 ID 和版本查找策略?RequestFactoryInterfaceValidator
getId()
getVersion()
我想我可以重写ServiceLayerDecorator.resolveClass()
以忽略“中毒”代理类,但在这一点上,我似乎在与框架作斗争太多......