2011-08-11 45 views
1

我目前正在JPA澤西Servlet工作和Im試圖使用Guice依賴注入。問題是,我得到了以下錯誤:谷歌Guice和JPA注入 - 奇怪的錯誤

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-persist 3.0和guice-servlet 3.0來使用Guice 3.0。應用程序工作的機器使用OpenJDK運行Ubuntu 11.04,出現問題的機器使用帶有JDK1.6v26的Windows 7。我通常使用Glassfish提供的Datasource,但即使使用普通的persistence.xml也不起作用。

我很困惑... 任何想法Guice Injection for JPA有什麼問題?

回答

2

因爲沒有人回答我去蠻力:

完全重新安裝Glassfish和Web應用程序的工作...

東西必須在這裏測試我的本地機器上的漫長歲月中已損壞。

+2

我重新發現,谷歌封閉模板jar通過混合guice 2.0和guice 3.0將guice顛倒......這使得兩個都不可能使用... – Johnnycube

+0

您的評論真的有幫助!有相同的錯誤,原因是我在一個maven版本中使用舊版本的TestNG以及guice 3。那個舊的TestNG jar裏面有guice 2 ...用最新的TestNG版本代替它,測試再次運行。再次感謝您給我正確的方向! –