java - class.getAnnotation 和 getAnnotations 不能正常工作

标签 java eclipse gwt annotations gwt-rpc

像这样从 gwt 类 SecureDispatchService:

@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
    Result execute( String sessionId, Action<?> action ) throws DispatchException;
}

RemoteServiceRelativePath:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemoteServiceRelativePath {
  /**
   * The relative path for the {@link RemoteService} implementation.
   * 
   * @return relative path for the {@link RemoteService} implementation
   */
  String value();
}

测试代码很简单:

package com.name.sbts.wbts.sm;

import net.customware.gwt.dispatch.client.secure.SecureDispatchService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

public class TestClass {

    public static void main(String[] args) {

        Class c = SecureDispatchService.class;
        System.out.println(c.getAnnotation(RemoteServiceRelativePath.class));
        System.out.println(c.getAnnotations().length);
    }
}

但是结果并不想要:

null
0

我在 eclipse 中使用 JRE1.7 运行这段代码

SecureDispatchService 在这个来自 google 的 jar 中:

gwt-dispatch-1.2.0.jar

我使用mvn eclipse:eclipse 来生成项目。 这个jar文件作为eclipse项目的引用库,它的真实路径在我的.m2/repostory中。

最佳答案

发生这种情况是因为 gwt-dispatch 项目是使用旧的 gwt-user 依赖项(gwt 版本 2.0.4)编译的。在这个版本的 gwt 中,RemoteServiceRelativePath注释没有 @Retention(RetentionPolicy.RUNTIME)在其上,因此 RemoteServiceRelativePath 注释在运行时不可用。

关于java - class.getAnnotation 和 getAnnotations 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29510159/

相关文章:

Java Jersey 不发送 ssl 客户端证书

java - 将 Eclipse Tomcat 日志重定向到控制台(没有 ConcoleAppender)

javascript - Vaadin自定义JS组件刷新率

java - 如何在 GWT 中有选择地打开 JSNI 部分?

java - 如何在图形 MPAndroidChart 上显示数据集?

java - BrightScript Eclipse 插件在 OSX 上安装后不显示

android - 在 Mac 上使用 Android SDK,Eclipse 真的很慢。我怎样才能加快速度?

java - GWT 和 GWTP 之间的区别

php - gwt ajax ssl登录

java - 如何更改按钮的 onClick() 行为?