Java + Hibernate4 + GWT + App Engine = InitialContext错误

时间:2012-03-13 13:47:40

标签: java hibernate google-app-engine gwt initial-context

我尝试使用GWT + hibernate4 + Apache Tomcat开发一个简单的webapp。 现在我用GWT&编写了我的简单类。 hibernate(第一次使用默认的App Engine服务器),但是在向服务器发送数据时出现错误,在课堂上出现了

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); 这是stacktrace

    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 个答案:

答案 0 :(得分:1)

正在发生的事情正如它所说:

“java.lang.NoClassDefFoundError:javax.naming.InitialContext是一个受限制的类。有关详细信息,请参阅Google App Engine开发人员指南。”

由于Google App Engine JRE白名单,您的代码不会像这样运行。换句话说,您不能使用可以运行Tomcat等“独立”Java应用服务器的所有Java类和库。

查看允许在Google App Engine上运行的应用程序中使用哪些Java类的精确列表:

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