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(); } }' –

相關問題