2012-03-13 40 views
1

我嘗試使用GWT + hibernate4 + Apache Tomcat開發簡單的webapp。 現在我已經寫了我的簡單的類與GWT &休眠(使用首次默認App Engine的服務器),但同時將數據發送到服務器,在課堂上界河棱Java + Hibernate4 + GWT + App Engine = InitialContext錯誤

public class HibernateUtil { 
private static SessionFactory sessionFactory; 
private static ServiceRegistry serviceRegistry; 

static SessionFactory getSessionFactory() throws HibernateException { 
    Configuration configuration = new Configuration(); 
    configuration.configure(); 
    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();   
    sessionFactory = configuration.buildSessionFactory(serviceRegistry); 
    return sessionFactory; 
} 

}

我得到一個錯誤

就行sessionFactory = configuration.buildSessionFactory(serviceRegistry); 這裏是堆棧跟蹤

java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details. 
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51) 
at org.hibernate.service.jndi.internal.JndiServiceImpl.buildInitialContext(JndiServiceImpl.java:77) 
at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:107) 
at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:79) 
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:440) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) 
at ru.leti.alexeeva.server.HibernateUtil.getSessionFactory(HibernateUtil.java:17) 

有沒有什麼辦法?

回答

1

發生了什麼事正是它說:

「java.lang.NoClassDefFoundError:javax.naming.InitialContext中是有限制類請參閱谷歌App Engine的開發者指南瞭解更多詳情。」

由於Google App Engine JRE白名單的存在,您的代碼不會像這樣開箱即用。換句話說,您不能使用所有可以運行「獨立」Java應用程序服務器(如Tomcat)的Java類和庫。

看看哪些Java類被允許在谷歌App Engine上運行的應用程序中使用精確的名單:

http://code.google.com/appengine/docs/java/jrewhitelist.html

+0

等?解決方案是什麼?你怎麼還能在gae + cloudsql上使用hibernate? – 2012-03-27 12:26:12

+1

@FabioB。 http://blog.essaytagger.com/2011/11/spring-hibernate-on-google-app-engines.html – alex 2012-03-27 16:00:46

+0

因爲你知道解決方案去這個問題http://stackoverflow.com/questions/9783773/spring -autowiring-stopped-working-on-gae並拿走我的50個賞金點,並有完整的答案! :D – 2012-03-28 06:33:20