【问题标题】:Google Guice and JPA Injection - Strange errorGoogle Guice 和 JPA 注入 - 奇怪的错误
【发布时间】:2011-08-11 21:56:32
【问题描述】:

我目前正在开发 JPA Jersey Servlet,我正在尝试使用 Guice 进行依赖注入。问题是,我收到以下错误:

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.google.inject.CreationException: Guice creation errors:

1) null returned by binding at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:63)
 but parameter 1 of com.google.inject.persist.jpa.JpaPersistService.<init>() is not @Nullable
  while locating java.util.Properties annotated with @com.google.inject.persist.jpa.Jpa()
   for parameter 1 at com.google.inject.persist.jpa.JpaPersistService.<init>(JpaPersistService.java:43)
 at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:67)
 while locating com.google.inject.persist.jpa.JpaPersistService
   for field at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.emProvider(JpaLocalTxnInterceptor.java:33)
 at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:76)

2) null returned by binding at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:63)
 but parameter 1 of com.google.inject.persist.jpa.JpaPersistService.<init>() is not @Nullable
  while locating java.util.Properties annotated with @com.google.inject.persist.jpa.Jpa()
    for parameter 1 at com.google.inject.persist.jpa.JpaPersistService.<init>(JpaPersistService.java:43)
  at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:67)
  while locating com.google.inject.persist.jpa.JpaPersistService
  while locating com.google.inject.persist.UnitOfWork 
    for field at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.unitOfWork(JpaLocalTxnInterceptor.java:36)
  at com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:76)
2 errors

我产生这个错误的代码是:

install(new JpaPersistModule("theseen")); 
filter("/*").through(PersistFilter.class);

如果我通过实例化 EntitiManager 并取消注释这些行来使用“标准”方式,则不会发生任何事情。

 EntityManagerFactory emf = Persistence
            .createEntityManagerFactory("theseen");
 EntityManager em = emf.createEntityManager();

 em.getTransaction().begin();
 em.merge(s);
 em.getTransaction().commit();

像魅力一样工作。所以我认为如果数据库连接必须没问题的设置。

这些错误可能是什么?我在另一个测试环境中测试了同一个应用程序,它可以工作!两台机器都使用 Glassfish 3.1、带有 m2eclipse 和 m2wtp 集成的 Eclipse Indigo。我将 Guice 3.0 与 guice-persist 3.0 和 guice-servlet 3.0 一起使用。应用程序运行的机器运行带有 OpenJDK 的 Ubuntu 11.04,出现问题的机器使用带有 JDK1.6v26 的 Windows 7。我通常使用 Glassfish 提供的数据源,但即使使用普通的 persistence.xml 也无法正常工作。

我真的很困惑... 任何想法 JPA 的 Guice 注入有什么问题?

【问题讨论】:

    标签: java servlets jpa jersey guice


    【解决方案1】:

    由于没有人回答,我就用蛮力:

    完全重新安装 Glassfish,WebApp 工作正常...

    在我的本地机器上进行长达数月的测试期间,一定有什么东西被破坏了。

    【讨论】:

    • 我突然发现 google 闭包模板 jar 通过将 guice 2.0 与 guice 3.0 混合起来将 guice 颠倒过来......这使得两者都无法使用......
    • 您的评论真的很有帮助!有同样的错误,原因是我在 maven 构建中使用了旧版本的 TestNG 和 guice 3。那个旧的 TestNG jar 里面有 guice 2...用最新的 TestNG 版本替换它,测试再次运行。再次感谢您给我正确的方向!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多