2017-10-13 48 views
0

我使用Lagom框架並通過mvn測試運行測試。測試失敗,出現com.google.inject.CreationException。棧跟蹤是運行lagom測試時的注射器錯誤

com.google.inject.CreationException: Unable to create injector, see 
the following errors: 

1) No implementation for 
com.lightbend.lagom.javadsl.persistence.PersistentEntityRegistry was 
bound. 
while locating 
com.lightbend.lagom.javadsl.persistence.PersistentEntityRegistry 
for parameter 0 at com.pv.svc.chat.impl.ChatServiceImpl.<init> 
(ChatServiceImpl.java:45) 
at 
com.lightbend.lagom.javadsl.server.ServiceGuiceSupport. 
bindServices(ServiceGuiceSupport.java:74) (via modules: 
com.google.inject.util.Modules$OverrideModule -> 
com.pv.svc.chat.impl.ChatServiceModule) 

2) No implementation for 
com.lightbend.lagom.javadsl.persistence.ReadSide was bound. 
while locating com.lightbend.lagom.javadsl.persistence.ReadSide 
for parameter 1 at com.pv.svc.chat.impl.ChatServiceImpl.<init> 
(ChatServiceImpl.java:45) 
at 
com.lightbend.lagom.javadsl.server.ServiceGuiceSupport. 
bindServices(ServiceGuiceSupport.java:74) (via modules: 
com.google.inject.util.Modules$OverrideModule -> 
com.pv.svc.chat.impl.ChatServiceModule) 

3) No implementation for 
com.lightbend.lagom.javadsl.persistence.jdbc.JdbcSession was bound. 
while locating 
com.lightbend.lagom.javadsl.persistence.jdbc.JdbcSession 
for parameter 2 at com.pv.svc.chat.impl.ChatServiceImpl.<init> 
(ChatServiceImpl.java:45) 
at 
com.lightbend.lagom.javadsl.server.ServiceGuiceSupport. 
bindServices(ServiceGuiceSupport.java:74) (via modules: 
com.google.inject.util.Modules$OverrideModule -> 
com.pv.svc.chat.impl.ChatServiceModule) 

3 errors 
at 

com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist 
(Errors.java:466) 
at 
com.google.inject.internal.InternalInjectorCreator. 
initializeStatically(InternalInjectorCreator.java:155) 
at 
com.google.inject.internal.InternalInjectorCreator.build 
(InternalInjectorCreator.java:107) 
at com.google.inject.Guice.createInjector(Guice.java:96) 
at com.google.inject.Guice.createInjector(Guice.java:84) 
at play.api.inject.guice.GuiceBuilder.injector 
(GuiceInjectorBuilder.scala:181) 
at play.inject.guice.GuiceBuilder.injector 
(GuiceBuilder.java:208) 
at play.inject.guice.GuiceApplicationBuilder.build 
(GuiceApplicationBuilder.java:127) 
at com.lightbend.lagom.javadsl.testkit.ServiceTest$.startServer 
(ServiceTest.scala:282) 
at com.lightbend.lagom.javadsl.testkit.ServiceTest.startServer 
(ServiceTest.scala) 
at com.pv.svc.chat.impl.ChatServiceTest.setUp 
(ChatServiceTest.java:28) 
at sun.reflect.NativeMethodAccessorImpl.invoke0 
(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke 
(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke 
(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall 
(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run 
(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively 
(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate 
(RunBefores.java:24) 
at org.junit.internal.runners.statements.RunAfters.evaluate 
(RunAfters.java:27) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.apache.maven.surefire.junit4.JUnit4Provider.execute 
(JUnit4Provider.java:252) 
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet 
(JUnit4Provider.java:141) 
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke 
(JUnit4Provider.java:112) 
at sun.reflect.NativeMethodAccessorImpl.invoke0 
(Native Method) 
..... 

據我所知,Lagom沒有在運行測試時注入依賴項。我正在使用JDBC持久實體和讀取端。有什麼辦法可以解決這個問題嗎?我的服務器設置爲測試

private static TestServer server; 

@BeforeClass 
public static void setUp() { 
    server = ServiceTest.startServer(defaultSetup()); 
} 

@AfterClass 
public static void tearDown() { 
    if (server != null) { 
     server.stop(); 
     server = null; 
    } 
} 

我知道卡桑德拉,我們必須使用defaultSetup()。withCassandra(真),但對於JDBC?我也使用Kakfa來接收消息。請幫忙。

+0

嗨shik9,Lagom的testkit只支持在目前(不JDBC)卡桑德拉後端。有關更新,請參閱https://github.com/lagom/lagom/issues/304。 – ignasi35

+0

Hi @ ignasi35,我認爲這是不可能的,但有沒有什麼辦法來模擬整個數據庫的事情。我需要三件事PersistentEntityRegistry,ReadSide和JdbcSession。 – konghoho

回答

0

您需要卡桑德拉添加到您的設置

@BeforeClass 
public static void setUp() { 
    server = ServiceTest.startServer(defaultSetup().withCassandra(true)); 
} 
相關問題