【问题标题】:Java + Hibernate4 + GWT + App Engine = InitialContext errorJava + Hibernate4 + GWT + App Engine = InitialContext 错误
【发布时间】:2012-03-13 13:47:40
【问题描述】:

我尝试使用 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); 这是堆栈跟踪

    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)

有什么办法吗?

【问题讨论】:

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


    【解决方案1】:

    所发生的正是它所说的:

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

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

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

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

    【讨论】:

    • 等等?有什么解决办法?你怎么还能在 gae+cloudsql 上使用休眠?
    • 既然您知道解决方案,请转到此问题stackoverflow.com/questions/9783773/… 并获取我的 50 赏金积分,并提供完整答案! :D
    • 我不是为了赏金,但他们昨天刚刚released SDK 1.6.4 支持 JPA 2 和 JDO 3,所以您的代码现在可以开箱即用。不过,新 SDK 版本可能需要几天时间才能在所有生产实例中传播。
    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 2012-01-10
    • 2011-02-24
    • 2014-08-09
    • 2013-06-17
    相关资源
    最近更新 更多