【发布时间】: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