【问题标题】:503 Error ObjectifyService NoSuchFieldError: WHITESPACE503 错误 ObjectifyService NoSuchFieldError:空白
【发布时间】:2017-10-26 20:12:49
【问题描述】:

更新

如果我删除配置文件 pojo 上的 @Cache 注释,它适用于开发环境。


原创

我的问题是,在使用 intellij 的 GAE 开发服务器中,当我尝试使用 objectify 从 de userId 创建密钥时遇到此错误

在 api 浏览器上

503 Service Unavailable

{
 "error": {
  "message": "java.lang.NoSuchFieldError: WHITESPACE",
  "code": 503,
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "java.lang.NoSuchFieldError: WHITESPACE"
   }
  ]
 }
}

Java 异常

java.lang.NoSuchFieldError: WHITESPACE
    at com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java:194)
    at com.googlecode.objectify.cache.KeyMemcacheService.keyify(KeyMemcacheService.java:46)
    at com.googlecode.objectify.cache.KeyMemcacheService.getIdentifiables(KeyMemcacheService.java:76)
    at com.googlecode.objectify.cache.EntityMemcache.getAll(EntityMemcache.java:245)
    at com.googlecode.objectify.cache.CachingAsyncDatastoreService.get(CachingAsyncDatastoreService.java:252)
    at com.googlecode.objectify.impl.LoadEngine.fetch(LoadEngine.java:168)
    at com.googlecode.objectify.impl.Round.fetchPending(Round.java:168)
    at com.googlecode.objectify.impl.Round.execute(Round.java:137)
    at com.googlecode.objectify.impl.LoadEngine.execute(LoadEngine.java:89)
    at com.googlecode.objectify.impl.Round$1.nowUncached(Round.java:70)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
    at com.googlecode.objectify.LoadResult.now(LoadResult.java:25)

另外,部署在应用引擎上我没有任何问题,它工作正常。我在 chrome 和 firefox 上试过。

我的代码是这样的

OfyService.java

static {
        try {
            factory().register(Profile.class);
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static Objectify ofy() {
        return ObjectifyService.ofy();
    }


    public static ObjectifyFactory factory() {
        return ObjectifyService.factory();
    }
}

Profile.java

@Entity
@Cache
public class Profile {
    String userName;
    String displayName;
    String mainEmail;

    @Id String userId;

    public Profile(String userId, String userName, String displayName, String mainEmail) {
        this.userId = userId;
        this.userName = userName;
        this.displayName = displayName;
        this.mainEmail = mainEmail;
    }

    public String getUserName() {
        return userName;
    }

    public String getDisplayName() {
        return displayName;
    }

    public String getMainEmail() {
        return mainEmail;
    }

    public String getUserId() {
        return userId;
    }

    private Profile() {
    }

    public void update(String userName, String displayName, String mainEmail) {
        if (userName != null) {
            this.userName = userName;
        }
        if (displayName != null) {
            this.displayName = displayName;
        }
        if (mainEmail != null) {
            this.mainEmail = mainEmail;
        }
    }

    public void updateName(String displayName) {
        if (displayName != null) {
            this.displayName = displayName;
        }
    }
}

MyApi.java

//region Profile
    @ApiMethod(name = "saveProfile", path = "profile", httpMethod = ApiMethod.HttpMethod.POST)
    public Profile saveProfile(final User user, ProfileForm profileForm)
            throws UnauthorizedException {
        if (user == null) {
            throw new UnauthorizedException("Authorization required");
        }
        String mainEmail = user.getEmail();
        String userId = user.getUserId();
        String displayName = profileForm.getDisplayName();

        Key<Profile> profileKey = Key.create(Profile.class, userId);
        Profile profile = ofy().load().key(profileKey).now();

        String userName = extractDefaultDisplayNameFromEmail(mainEmail);
        if (profile == null) {
        ...

在这一行

Profile profile = ofy().load().key(profileKey).now();

我正在使用这个版本(并尝试过其他版本):

  • appengine-api-1.0-sdk:1.9.53
  • appengine-endpoints:1.9.53
  • guava:22.0-android
  • 物化:5.1.16

还有这个其他版本:

  • jdk: 1.8.0_121
  • 智能 2017.1.3
  • 谷歌云 SDK 156.0.0
    • app-engine-java 1.9.53
    • app-engine-python 1.9.53
    • bq 2.0.24
    • 云数据存储模拟器 1.2.1
    • 核心2017.05.19
    • gcloud
    • gsutil 4.26

【问题讨论】:

    标签: java google-app-engine intellij-idea google-cloud-datastore google-cloud-endpoints


    【解决方案1】:

    如果应用程序尝试访问或修改对象的指定字段,并且该对象不再具有该字段或也已更改(通常部分编译或其他依赖项目中的相同类),则会抛出此 error。 尝试在更改之前识别该字段来自的所有类并更新您的所有项目,即使通常现代 IDE 会为您执行此操作,简单的清理和构建也可以解决问题。

    【讨论】:

    • 你能不能换一种说法解释一下这个“尝试识别出现的类,该类在更改之前来自该字段的所有类”
    • @Niesteszeck 是一个类的字段,尝试知道该字段在哪个类中
    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 2018-11-22
    • 2017-07-07
    • 1970-01-01
    相关资源
    最近更新 更多