0

在获得有关 [获取服务侦听][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

4

1 回答 1

1

似乎你有 maven dep 问题。在父 pom.xml 你有:

 <lagom.version>1.3.0-M1</lagom.version>

这个版本由 lagom maven 插件使用。

另一方面,您所有的 lagom 依赖项都使用 1.2.1 版:

    <dependency>
        <groupId>com.lightbend.lagom</groupId>
        <artifactId>lagom-javadsl-persistence_2.11</artifactId>
        <version>1.2.1</version>
    </dependency>

尝试将其更改为:

   <dependency>
        <groupId>com.lightbend.lagom</groupId>
        <artifactId>lagom-javadsl-persistence_2.11</artifactId>
        <version>${lagom.version}</version>
    </dependency>

为所有其他 lagom 部门执行此操作。

更新

您的另一个问题似乎是 2 个持久性提供程序

<dependency>
    <groupId>com.lightbend.lagom</groupId>
    <artifactId>lagom-javadsl-persistence-jdbc_2.11</artifactId>
</dependency>
<dependency>
    <groupId>com.lightbend.lagom</groupId>
    <artifactId>lagom-javadsl-persistence-cassandra_2.11</artifactId>
</dependency>

从 pom(s).xml中删除对lagom-javadsl-persistence-jdbc_2.11 的依赖(尤其是 actor-impl/pom.xml)

你也不需要他们中的任何一个 actor-api/pom.xml 从com.lightbend.lagom离开那里只有lagom-javadsl-api_2.11

于 2017-01-19T22:08:56.533 回答