在获得有关 [获取服务侦听][1] 的帮助后,之前尝试运行初始 lagom 服务失败。
因此,在这次尝试中,maven 项目(usvcs)只有两个模块(actor-api 和 actor-impl)和一个服务调用“echo”。
public interface MAIActorsService extends Service {
ServiceCall<NotUsed, String> echo(String s);
@Override
default Descriptor descriptor() {
// @formatter:off
return named("cmai_actors").withCalls(
restCall(Method.GET, "/echo/:s", this::echo)
).withAutoAcl(true);
// @formatter:on
}
}
并且实现是一个没有实体引用的存根。
@Override
public ServiceCall<NotUsed, String> echo(String s) {
return request -> {
CompletableFuture<String> alreadyCompleted = CompletableFuture.completedFuture(s);
try {
alreadyCompleted.get();
} catch (Exception e) {
e.printStackTrace();
}
return alreadyCompleted;
};
}
运行 'mvn lagom:runAll' 抛出异常,并指出未找到内部lagom dsl 类。
$ mvn lagom:runAll
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] usvcs
[INFO] actor-api
[INFO] actor-impl
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building usvcs 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- lagom-maven-plugin:1.3.0-M1:runAll (default-cli) @ usvcs ---
[INFO] Starting Kafka
[INFO] Starting Cassandra
.[INFO] Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
.........[INFO] Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
[INFO] New Cassandra host /127.0.0.1:4000 added
[INFO] Cassandra server running at 127.0.0.1:4000
[INFO] Service locator is running at http://localhost:8000
[INFO] Service gateway is running at http://localhost:9000
No play.logger.configurator found: logging must be configured entirely by the application.
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\lusp\maisvc\usvcs\actor-api\src\main\resources
[INFO] Nothing to compile - all classes are up to date
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Nothing to compile - all classes are up to date
java.lang.NoClassDefFoundError: com/lightbend/lagom/internal/javadsl/api/broker/TopicFactoryProvider
at com.lightbend.lagom.internal.javadsl.registry.ServiceRegistryModule.configure(ServiceRegistryModule.scala:35)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
at com.google.inject.spi.Elements.getElements(Elements.java:110)
at com.google.inject.util.Modules$OverrideModule.configure(Modules.java:177)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
at com.google.inject.spi.Elements.getElements(Elements.java:110)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
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.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2$$anonfun$3.apply(LagomReloadableDevServerStart.scala:151)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2$$anonfun$3.apply(LagomReloadableDevServerStart.scala:148)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2.apply(LagomReloadableDevServerStart.scala:148)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2.apply(LagomReloadableDevServerStart.scala:124)
at scala.Option.map(Option.scala:146)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1.apply(LagomReloadableDevServerStart.scala:124)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1.apply(LagomReloadableDevServerStart.scala:122)
at scala.util.Success.flatMap(Try.scala:231)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1.apply(LagomReloadableDevServerStart.scala:122)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1.apply(LagomReloadableDevServerStart.scala:114)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: com.lightbend.lagom.internal.javadsl.api.broker.TopicFactoryProvider
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Stacktrace caused by project target (filesystem path to project is C:\Users\lusp\maisvc\usvcs\actor-impl\target).
[INFO] Service actor-impl listening for HTTP on 0:0:0:0:0:0:0:0:62728
[INFO] (Service started, press enter to stop and go back to the console...)
该服务不起作用,明显的问题是是否不允许存根服务调用???
更新
做了一些改动,还是报错,所以我把代码放在github上,以便更完整地记录下来https://github.com/tevye/lagom-echo-project-from-scratch