在运行lagom测试喷油器错误

问题描述 投票:0回答:2

我使用Lagom框架和运行通过MVN测试的测试。测试失败,com.google.inject.CreationException。堆栈跟踪为

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以及用于接收消息。请帮忙。

java jdbc lagom
2个回答
0
投票

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

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

0
投票

您可以添加卡桑德拉选项,您build.sbt:

lagomCassandraEnabled in ThisBuild := true

和任选的任何以下选项:

lagomCassandraPort in ThisBuild := 9042
lagomCassandraCleanOnStart in ThisBuild := true
lagomCassandraYamlFile in ThisBuild := Some((baseDirectory in ThisBuild).value / "project" / "cassandra.yml")

加入Dependencies.scala(如果使用):

import com.lightbend.lagom.sbt.LagomImport.{......, lagomJavadslPersistenceCassandra}

并增加服务实现依赖关系:

 val implYourServiceName= Seq(
    .......
    lagomJavadslPersistenceCassandra,
    ......
  )

Outwise(不依赖文件)添加到build.sbt后续的依赖关系:

lazy val `your-service-name-impl` = project("your-service-name-impl")
  .enablePlugins( .... your plugins here ....)
  .settings(libraryDependencies ++= Seq(
    .......
    lagomJavadslPersistenceCassandra,
    ......))
© www.soinside.com 2019 - 2024. All rights reserved.