1

我卡在数据存储上。带数据存储的Google端点:java.lang.ExceptionInInitializerError

我想用数据存储运行Google终点。

mvn appengine:update命令后,我可以看到我的方法在资源管理器,但它没有得到执行,因为它有错误。

这里是错误:

java.lang.ExceptionInInitializerError 

这里是我的功能,我试图执行:

@ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST) public Profile saveProfile(final User user, ProfileForm profileForm) throws UnauthorizedException { TeeShirtSize teeShirtSize = TeeShirtSize.NOT_SPECIFIED; if (user == null) { throw new UnauthorizedException("Authorization required"); } String userId = user.getUserId(); String mainEmail = user.getEmail(); String displayName = profileForm.getDisplayName(); if (profileForm.getTeeShirtSize() != null) { teeShirtSize = profileForm.getTeeShirtSize(); } if (displayName == null) { displayName = extractDefaultDisplayNameFromEmail(user.getEmail()); } Profile profile = new Profile(userId, displayName, mainEmail, teeShirtSize);ofy().save().entity(profile).now(); return profile; }

回答

0

你忘了注册客体。做一个启动的servlet像

import com.googlecode.objectify.ObjectifyService; 

public class StartupServlet extends HttpServlet { 

    static { 
    ObjectifyService.register(Profile.class); 
    } 
} 

,并在web.xml登记

<servlet> 
    <servlet-name>startup</servlet-name> 
    <servlet-class>full.package.StartupServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

编辑:

我想你已经从OFY谷歌图书馆再出现在您的代码片断输入,更改到:

OfySevice.ofy().save().entity(profile).now(); 
+0

我已经创建了一个名为“OfyService.java”的文件..它是该文件的代码: –

+0

在这个,我已经包括以下东西:package com.google.devrel.training.conference.service; import com.google.devrel.training.conference.domain.Profile; import com.googlecode.objectify.Objectify; import com.googlecode.objectify.ObjectifyFactory; import com.googlecode.objectify.ObjectifyService; –

+0

'public class OfyService {0} {static} {objctifyService.register(Profile.class); } public static Objectify ofy(){ return ObjectifyService.ofy(); (){ } public static ObjectifyFactory factory(){ return ObjectifyService.factory(); } }' –