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

时间:2012-03-24 16:11:55

标签: 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]          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

除了注释之外,我没有引用任何服务器端类:

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);
    }

}

1 个答案:

答案 0 :(得分:3)

我在一段时间后遇到了同样的问题。您的代码没有任何问题。默认情况下,GWT编译器不会包含用于编译的注释引用的类,这很疯狂。所以,你看到AnnotatedRfqService cannot be resolved to a type的原因是因为那些类实际上根本没有被编译。解决方案是在尝试编译GWT模块之前运行Java编译器(通过Ant,可能是)编译所有内容。

我在这里问(并回答)同样的问题:https://stackoverflow.com/a/8766677/291180

出于某种原因,GWT忽略了该类型的import语句,但他们并不认为这是一个错误。荒谬。 http://code.google.com/p/google-web-toolkit/issues/detail?id=5378