GWT RequestFactory:在客户端包中使用服务器类

GWT RequestFactory:在客户端包中使用服务器类,gwt,requestfactory,Gwt,Requestfactory,GWT in Action,2ed(MEAP),第218页说,我们可以在客户端代码中引用注释中的服务器端类,如@ProxyFor。这是合乎逻辑的,也是我所期望的。。。但是,我从gwt编译器中得到了异常: Validating newly compiled units [ant:java] Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/AppRequestFactory.java' [ant:java]

GWT in Action,2ed(MEAP),第218页说,我们可以在客户端代码中引用注释中的服务器端类,如@ProxyFor。这是合乎逻辑的,也是我所期望的。。。但是,我从gwt编译器中得到了异常:

Validating newly compiled units
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/AppRequestFactory.java'
[ant:java]          Line 9: The import de.mycompany.server.AnnotatedRfqServiceLocator cannot be resolved
[ant:java]          Line 10: The import de.mycompany.server.dao.AnnotatedRfqService cannot be resolved
[ant:java]          Line 15: AnnotatedRfqService cannot be resolved to a type
[ant:java]          Line 15: AnnotatedRfqServiceLocator cannot be resolved to a type
[ant:java]          Line 15: Class<AnnotatedRfqServiceLocator> cannot be resolved to a type
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/proxy/AnnotatedRfqProxy.java'
[ant:java]          Line 9: The import de.mycompany.server.AnnotatedRfqServiceLocator cannot be resolved
[ant:java]          Line 10: The import de.mycompany.server.domain.AnnotatedRfq cannot be resolved
[ant:java]          Line 12: AnnotatedRfq cannot be resolved to a type
[ant:java]          Line 12: AnnotatedRfqServiceLocator cannot be resolved to a type
[ant:java]          Line 12: Class<AnnotatedRfqServiceLocator> cannot be resolved to a type
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/proxy/AnnotationProxy.java'
[ant:java]          Line 6: The import de.mycompany.server.domain.Annotation cannot be resolved
[ant:java]          Line 8: Annotation cannot be resolved to a type
[ant:java]    Removing invalidated units
验证新编译的单元
“文件:/C:/git/mvp\u ap\u test/src/de/mycompany/client/AppRequestFactory.java”中的[ant:java]错误
[ant:java]第9行:无法解析导入de.mycompany.server.AnnotatedRfqServiceLocator
[ant:java]第10行:无法解析导入de.mycompany.server.dao.AnnotatedRfqService
[ant:java]第15行:无法将AnnotatedRfqService解析为类型
[ant:java]第15行:无法将AnnotatedRfqServiceLocator解析为类型
[ant:java]第15行:无法将类解析为类型
“文件:/C:/git/mvp\u ap\u test/src/de/mycompany/client/proxy/AnnotatedRfqProxy.java”中的[ant:java]错误
[ant:java]第9行:无法解析导入de.mycompany.server.AnnotatedRfqServiceLocator
[ant:java]第10行:无法解析导入de.mycompany.server.domain.AnnotatedRfq
[ant:java]第12行:无法将AnnotatedRfq解析为类型
[ant:java]第12行:AnnotatedRfqServiceLocator无法解析为类型
[ant:java]第12行:无法将类解析为类型
“文件:/C:/git/mvp\u ap\u test/src/de/mycompany/client/proxy/AnnotationProxy.java”中的[ant:java]错误
[ant:java]第6行:无法解析导入de.mycompany.server.domain.Annotation
[ant:java]第8行:无法将注释解析为类型
[ant:java]删除无效单元
除注释外,我不引用任何服务器端类:

package de.mycompany.client;

import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.Service;

import de.mycompany.client.proxy.AnnotatedRfqProxy;
import de.mycompany.server.AnnotatedRfqServiceLocator;
import de.mycompany.server.dao.AnnotatedRfqService;

public interface AppRequestFactory extends RequestFactory {
    AnnotatedRfqRequest annotatedRfqRequest();

    @Service(value = AnnotatedRfqService.class, locator = AnnotatedRfqServiceLocator.class)
    public interface AnnotatedRfqRequest extends RequestContext {
       Request<AnnotatedRfqProxy> findOne(String id);
    }

}
package de.mycompany.client;
导入com.google.web.bindery.requestfactory.shared.Request;
导入com.google.web.bindery.requestfactory.shared.RequestContext;
导入com.google.web.bindery.requestfactory.shared.requestfactory;
导入com.google.web.bindery.requestfactory.shared.Service;
导入de.mycompany.client.proxy.drfqproxy;
导入de.mycompany.server.AnnotatedRfqServiceLocator;
导入de.mycompany.server.dao.drfqservice;
公共接口AppRequestFactory扩展了RequestFactory{
AnnotatedRfqRequest AnnotatedRfqRequest();
@服务(值=AnnotatedRfqService.class,定位器=AnnotatedRfqServiceLocator.class)
公共接口AnnotatedRfqRequest扩展了RequestContext{
请求findOne(字符串id);
}
}

不久前我遇到了同样的问题。你的代码没有问题。默认情况下,GWT编译器将不包含注释引用的类进行编译,这很疯狂。因此,您看到的
AnnotatedRfqService无法解析为类型
,原因是这些类实际上根本没有被编译。解决方案是在尝试编译GWT模块之前运行Java编译器(大概通过Ant)编译所有内容

我在这里问(并回答)了同样的问题:

由于某种原因,GWT忽略了该类型的<代码>导入< /代码>语句,但他们不认为这是一个bug。可笑