我得到的错误可能是由于缺少配置,模块不兼容,......几个小时后我无法弄明白。
在sbt runAll
上,我得到以下堆栈跟踪:
com.google.inject.CreationException:无法创建注入器,请参阅 以下错误:
1)自定义提供程序中的错误,scala.MatchError:消息(类 sun.reflect.generics.reflectiveObjects.TypeVariableImpl)at com.lightbend.lagom.javadsl.server.ServiceGuiceSupport.bindServices(ServiceGuiceSupport.java:106) (通过模块:com.google.inject.util.Modules $ OverrideModule - > UserModule)在定位时 com.lightbend.lagom.internal.javadsl.server.ResolvedServices for com.lightbend.lagom.internal.server.ServiceRegistrationModule $ RegisterWithServiceRegistry的第二个参数。(ServiceRegistrationModule.scala:56) 在 com.lightbend.lagom.internal.server.ServiceRegistrationModule.bindings(ServiceRegistrationModule.scala:29): 绑定(类 com.lightbend.lagom.internal.server.ServiceRegistrationModule $ RegisterWithServiceRegistry 自我热切地)(通过模块: com.google.inject.util.Modules $ OverrideModule - > play.api.inject.guice.GuiceableModuleConversions $$ anon $ 1)while 定位 com.lightbend.lagom.internal.server.ServiceRegistrationModule $ RegisterWithServiceRegistry
1错误 com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470) 在 com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184) 在 com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) 在com.google.inject.Guice.createInjector(Guice.java:99)at com.google.inject.Guice.createInjector(Guice.java:84)at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185) 在 play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137) 在 play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) 在 play.core.server.LagomReloadableDevServerStart $$不久$ 1. $ anonfun $ $ 5美元(LagomReloadableDevServerStart.scala:176) at play.utils.Threads $ .withContextClassLoader(Threads.scala:21)at at play.core.server.LagomReloadableDevServerStart $$不久$ 1. $ anonfun $得到$ 3(LagomReloadableDevServerStart.scala:173) 在scala.Option.map(Option.scala:146)at play.core.server.LagomReloadableDevServerStart $$不久$ 1. $ anonfun $得到$ 2(LagomReloadableDevServerStart.scala:149) 在scala.util.Success.flatMap(Try.scala:247)at play.core.server.LagomReloadableDevServerStart $$不久$ 1. $ anonfun $获得$ 1(LagomReloadableDevServerStart.scala:147) 在scala.concurrent.Future $。$ anonfun $ apply $ 1(Future.scala:655)at at scala.util.Success。$ anonfun $ map $ 1(Try.scala:251)at scala.util.Success.map(Try.scala:209)at scala.concurrent.Future。$ anonfun $ map $ 1(Future.scala:289)at at scala.concurrent.impl.Promise.liftedTree1 $ 1(Promise.scala:29)at at 。scala.concurrent.impl.Promise $ anonfun $变换$ 1(Promise.scala:29) 在scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)at at java.util.concurrent.ForkJoinTask $ RunnableExecuteAction.exec(ForkJoinTask.java:1402) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) 在 java.util.concurrent.ForkJoinPool $ WorkQueue.runTask(ForkJoinPool.java:1056) 在 java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) 在 java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) 引起:scala.MatchError:消息(类 sun.reflect.generics.reflectiveObjects.TypeVariableImpl)at 。com.lightbend.lagom.internal.javadsl.api.CallResolver $ $ anonfun registeredMessageSerializerFor $ 1(ServiceCallResolver.scala:46) 在scala.Option.orElse(Option.scala:289)at com.lightbend.lagom.internal.javadsl.api.CallResolver.registeredMessageSerializerFor(ServiceCallResolver.scala:44) 在 com.lightbend.lagom.internal.javadsl.api.CallResolver.messageSerializerFor(ServiceCallResolver.scala:26) 在 com.lightbend.lagom.internal.javadsl.api.CallResolver.resolveMessageSerializer(ServiceCallResolver.scala:17) 在 。com.lightbend.lagom.internal.javadsl.api.ServiceReader $ $ $ anonfun $ resolveServiceDescriptor 4(ServiceReader.scala:200) 在 。scala.collection.TraversableLike $ anonfun $地图$ 1(TraversableLike.scala:234) 在scala.collection.Iterator.foreach(Iterator.scala:929)at scala.collection.Iterator.foreach $(Iterator.scala:929)at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)at scala.collection.IterableLike.foreach(IterableLike.scala:71)at scala.collection.IterableLike.foreach $(IterableLike.scala:70)at scala.collection.AbstractIterable.foreach(Iterable.scala:54)at scala.collection.TraversableLike.map(TraversableLike.scala:234)at scala.collection.TraversableLike.map $(TraversableLike.scala:227)at scala.collection.AbstractTraversable.map(Traversable.scala:104)at com.lightbend.lagom.internal.javadsl.api.ServiceReader $ .resolveServiceDescriptor(ServiceReader.scala:158) 在 com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder.resolveDescriptor(JavadslServerBuilder.scala:69) 在 。com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder $ anonfun $ resolveServices $ 1(JavadslServerBuilder.scala:56) 在 。scala.collection.TraversableLike $ anonfun $地图$ 1(TraversableLike.scala:234) 在 scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59) 在 scala.collection.mutable.ResizableArray.foreach $(ResizableArray.scala:52) 在scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) 在scala.collection.TraversableLike.map(TraversableLike.scala:234) 在scala.collection.TraversableLike.map $(TraversableLike.scala:227) 在scala.collection.AbstractTraversable.map(Traversable.scala:104) 在 com.lightbend.lagom.internal.javadsl.server.JavadslServerBuilder.resolveServices(JavadslServerBuilder.scala:50) 在 com.lightbend.lagom.internal.javadsl.server.ResolvedServicesProvider.get $ lzycompute(JavadslServerBuilder.scala:112) 在 com.lightbend.lagom.internal.javadsl.server.ResolvedServicesProvider.get(JavadslServerBuilder.scala:111) 在 com.lightbend.lagom.internal.javadsl.server.ResolvedServicesProvider.get(JavadslServerBuilder.scala:105) 在 com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) 在 com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53) 在 com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61) 在 com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45) 在 com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38) 在 com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62) 在 com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110) 在 com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90) 在 com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:268) 在 com.google.inject.internal.ProviderToInternalFactoryAdapter $ 1.call(ProviderToInternalFactoryAdapter.java:46) 在 com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) 在 com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) 在 com.google.inject.internal.SingletonScope $ 1.get(SingletonScope.java:194) 在 com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) 在 com.google.inject.internal.InternalInjectorCreator $ 1.call(InternalInjectorCreator.java:205) 在 com.google.inject.internal.InternalInjectorCreator $ 1.call(InternalInjectorCreator.java:199) 在 com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085) 在 com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199) 在 com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180) ......还有25个
由项目user-impl引起的Stacktrace(项目的文件系统路径是 / Users / kimgysen / Documents / project livefeed / lagom / api-v1 / user-impl)。 提示:可能您忘记通过启用服务模块类
play.modules.enabled
? (检查你的项目&application.conf)
我的application.conf定义了:
play.modules.enabled += UserModule
我按照可用的示例来定义我的模块:
public class UserModule extends AbstractModule implements ServiceGuiceSupport {
@Override
protected void configure() {
bindService(UserService.class, UserServiceImpl.class);
}
}
我的sbt.build文件也非常简单:
organization in ThisBuild := "be.zwoop"
scalaVersion in ThisBuild := "2.12.4"
lagomKafkaEnabled in ThisBuild := true
import scala.concurrent.duration._ // Mind that the import is needed.
lagomCassandraMaxBootWaitingTime in ThisBuild := 50000.seconds
lazy val userApi = project("user-api")
.settings(
version := "1.0-SNAPSHOT",
libraryDependencies ++= Seq(
lagomJavadslApi,
lombok
)
)
lazy val userImpl = project("user-impl")
.enablePlugins(LagomJava)
.settings(
version := "1.0-SNAPSHOT",
libraryDependencies ++= Seq(
lagomJavadslPersistenceCassandra
)
)
.dependsOn(userApi)
val lombok = "org.projectlombok" % "lombok" % "1.16.20"
def project(id: String) = Project(id, base = file(id))
我只定义了一个插件:
addSbtPlugin("com.lightbend.lagom" % "lagom-sbt-plugin" % "1.4.4")
感谢您的建议。
修改我的服务外观:
public interface UserService extends Service {
String REGISTER_USER_TOPIC = "users";
ServiceCall<User, String> registerUser();
@Override
default Descriptor descriptor() {
return named("user").withCalls(
pathCall("/api/user", this::registerUser)
).withPathParamSerializer(
UUID.class, PathParamSerializers.required("UUID", UUID::fromString, UUID::toString)
).withTopics(
topic(REGISTER_USER_TOPIC, this::UserTopic)
).withAutoAcl(true);
}
Topic UserTopic();
}
答案 0 :(得分:0)
这里可以改进Lagom中的错误报告,但问题是UserService
中的服务调用正在使用类型变量。例如,您的API中可能包含以下内容:
public <Message> ServiceCall<Message, Foo> foo();
基本上,Lagom无法从中构建服务描述符,因为它不知道Message
的类型。