Google Guice 和 JPA 注入 - 奇怪的错误

发布于 2024-11-29 07:41:21 字数 2762 浏览 0 评论 0原文

我目前正在开发 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、Eclipse Indigo 以及 m2eclipse 和 m2wtp 集成。我将 Guice 3.0 与 guice-persist 3.0 和 guice-servlet 3.0 一起使用。该应用程序运行的计算机运行带有 OpenJDK 的 Ubuntu 11.04,出现问题的计算机使用带有 JDK1.6v26 的 Windows 7。我通常使用 Glassfish 提供的数据源,但即使使用普通的 persistence.xml 也不起作用。

我很困惑...... 你知道 JPA 的 Guice 注入有什么问题吗?

Im currently working on a JPA Jersey Servlet and Im trying to use Guice for dependency injection. The Problem is, that I get the following error:

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

The code that i generating this error is:

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

If I use the "standard" way by instantiating a EntitiManager and uncommenting these lines, nothing happens.

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

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

works like a charm. So I think the setup if the database connection must be ok.

What could these to errors possibly be? I tested the same App on another test environment and it works! Both machines use Glassfish 3.1, Eclipse Indigo with m2eclipse and m2wtp integration. I use Guice 3.0 with guice-persist 3.0 and guice-servlet 3.0. The machine where the app is working runs Ubuntu 11.04 with OpenJDK, the machine where problems occure uses Windows 7 with JDK1.6v26. I normally use a Datasource provided by Glassfish, but even using a plain persistence.xml is not working.

I am seriously confused...
Any ideas what is wrong with Guice Injection for JPA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2024-12-06 07:41:21

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

完全重新安装 Glassfish,WebApp 就可以工作了……

在我的本地计算机上进行长达数月的测试期间,某些东西一定已损坏。

Since nobody answered I went brute force:

Completely reinstall Glassfish and the WebApp worked...

Something must have been corrupted during the long months of testing here on my local machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文