gpt4 book ai didi

java - 运行 lagom 测试时喷油器错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:36 24 4
gpt4 key购买 nike

我正在使用 Lagom 框架并通过 mvn test 运行测试。测试失败并出现 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 在运行测试时不会注入(inject)依赖项。我将 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;
}
}

我知道对于 Cassandra,我们必须使用 defaultSetup().withCassandra(true),但是 JDBC 呢?我也使用 Kakfa 来接收消息。请帮忙。

最佳答案

您需要将 Cassandra 添加到您的设置中

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

关于java - 运行 lagom 测试时喷油器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46738801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com