akka.UnsupportedAkkaVersion:Akka的当前版本是[2.5.14],但akka-http需要版本[2.5.26]

1yjd4xko  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(92)

下面是类:

import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.model.ContentTypes;
import akka.http.javadsl.model.HttpEntities;
import akka.http.javadsl.model.HttpHeader;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.http.javadsl.server.AllDirectives;
import akka.http.javadsl.server.Route;
import akka.stream.ActorMaterializer;
import akka.stream.javadsl.Flow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

public class Ge extends AllDirectives
{

    private static String host = "localhost";
    private static int port = 8080;
    private static List<HttpHeader> headers;

    public static void main(String[] args) throws Exception
    {
        // boot up server using the route as defined below
        ActorSystem system = ActorSystem.create();

        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);
        //In order to access all directives we need an instance where the routes are define.

        Ge ge = new Ge();

        final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = gridUpdateService.createRoute().flow(system, materializer);

        http.bindAndHandle(routeFlow,
                ConnectHttp.toHost(host, port), materializer);

    }

    private Route createRoute()
    {
        return  route(
                        path(
                                "spec", () ->
                                        get(() -> complete(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, "Ok"))
                                        )
                        )
                );
    }

}

以下是build.gradle中的依赖项:

compile group: 'com.typesafe.akka', name: 'akka-http_2.12', version: '10.1.5'
compile group: 'com.typesafe.akka', name: 'akka-cluster_2.12', version: '2.5.14'

我不知道为什么会发生这个错误,即使我在这里提到,并发现这些版本应该是兼容的,如下面的文档链接中提到的:
与Akka HTTP 10.1.x的兼容性Akka HTTP 10.1.x(二进制)兼容Akka〉= 2.5.11以及在Akka HTTP 10.1.x生命周期内发布的未来Akka 2.x版本。
https://doc.akka.io/docs/akka-http/current/compatibility-guidelines.html
不幸的是,我不能更新akka版本,它必须是2.5.14,因为它是父项目的版本,改变它可能会破坏其他子项目的东西。2有什么办法可以让akka http与akka版本2.5.14一起工作吗?
以下是完整的堆栈跟踪:

Exception in thread "main" akka.UnsupportedAkkaVersion: Current version of Akka is [2.5.14], but akka-http requires version [2.5.26]
    at akka.AkkaVersion$.require(AkkaVersion.scala:43)
    at akka.AkkaVersion$.require(AkkaVersion.scala:23)
    at akka.http.scaladsl.HttpExt.<init>(Http.scala:57)
    at akka.http.scaladsl.Http$.createExtension(Http.scala:1123)
    at akka.http.scaladsl.Http$.createExtension(Http.scala:892)
    at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:913)
    at akka.actor.ExtensionId.apply(Extension.scala:79)
    at akka.actor.ExtensionId.apply$(Extension.scala:78)
    at akka.http.scaladsl.Http$.apply(Http.scala:1118)
    at akka.http.scaladsl.Http$.apply(Http.scala:892)
    at akka.http.javadsl.Http.delegate$lzycompute(Http.scala:45)
    at akka.http.javadsl.Http.delegate(Http.scala:45)
    at akka.http.javadsl.Http.defaultServerHttpContext(Http.scala:852)
    at akka.http.javadsl.Http.bindAndHandle(Http.scala:232)
    at com.dummy.ui.Ge.startHttp(Ge.java:55)

由于我不得不审查一些代码,因此行号会有所不同。

izkcnapc

izkcnapc1#

这个问题不是akka的问题,而是我的项目中陈旧的依赖关系的问题。
我早些时候曾尝试使用

compile group: 'com.typesafe.akka', name: 'akka-http_2.13', version: '10.1.5'

它必须已经下载了依赖项,并且正被用于启动项目。
我做了gradle --refresh-dependencies,解决了这个问题。
请确保查看文档以了解模块的兼容性,并清理缓存,然后重新下载所有依赖项。

相关问题