微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于数字孪生的 Azure Function App 中的 NoClassDefFoundError

如何解决用于数字孪生的 Azure Function App 中的 NoClassDefFoundError

我正在开发一个 azure 函数应用。 azure 函数应用程序中的函数负责从 azure 事件中心接收消息。此方法应更新 azure 数字孪生。我正在创建 Azure DigitalTwin 实例,如下所示

@FunctionName("eventGridMonitorString")
    public void eventHubProcessor(
            @EventHubTrigger(name = "msg",eventHubName = "",connection = "EventHubConnectionString") String message,final ExecutionContext context) {
//      context.getLogger().info(message);
        String adtUrl = System.getenv("ADT_SERVICE_URL");
        context.getLogger().info("ADTURl : " + adtUrl);

        DigitalTwinsClient client = new DigitalTwinsClientBuilder().credential(new ClientSecretCredentialBuilder()
                .tenantId("my_tenant_id").clientId("my_client_id")
                .clientSecret("my_client_secret").build()).endpoint(adtUrl).buildClient();

        Iterable<DigitalTwinsModelData> modelList = client.listModels();
        Iterator<DigitalTwinsModelData> it = modelList.iterator();
        while (it.hasNext()) {
            DigitalTwinsModelData model = it.next();
            context.getLogger().info("" + model.getDtdlModel());
        }
        for (DigitalTwinsModelData model : modelList) {
            context.getLogger().info("Created model: " + model.getModelId());
        }

    }

代码在我的本地 java 应用程序中运行良好,但是当我将此代码部署到 azure 函数应用程序时,它给了我以下错误

2021-05-27T07:42:35.173 [Error] Executed 'Functions.eventGridMonitorString' (Failed,Id=12a87102-78a3-4e2e-8715-b4401091d753,Duration=116ms)Result: FailureException: NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientConfigStack: java.lang.reflect.InvocationTargetExceptionat 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 com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)at com.microsoft.azure.functions.worker.broker.JavaMethodExecutorImpl.execute(JavaMethodExecutorImpl.java:54)at com.microsoft.azure.functions.worker.broker.JavaFunctionbroker.invokeMethod(JavaFunctionbroker.java:57)at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)Caused by: java.lang.NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientConfigat reactor.netty.http.client.HttpClientConnect.<init>(HttpClientConnect.java:84)at reactor.netty.http.client.HttpClient.create(HttpClient.java:393)at com.azure.core.http.netty.NettyAsyncHttpClientBuilder.build(NettyAsyncHttpClientBuilder.java:91)at com.azure.core.http.netty.implementation.ReactorNettyClientProvider.createInstance(ReactorNettyClientProvider.java:14)at com.azure.core.implementation.http.HttpClientProviders.createInstance(HttpClientProviders.java:58)at com.azure.core.http.HttpClient.createDefault(HttpClient.java:50)at com.azure.core.http.HttpClient.createDefault(HttpClient.java:40)at com.azure.core.http.HttpPipelineBuilder.build(HttpPipelineBuilder.java:62)at com.azure.digitaltwins.core.DigitalTwinsClientBuilder.buildPipeline(DigitalTwinsClientBuilder.java:151)at com.azure.digitaltwins.core.DigitalTwinsClientBuilder.buildAsyncclient(DigitalTwinsClientBuilder.java:193)at com.azure.digitaltwins.core.DigitalTwinsClientBuilder.buildClient(DigitalTwinsClientBuilder.java:160)at com.ey.azurefunctions.PolarDelightFunctionApp.Function.eventHubProcessor(Function.java:32)... 16 more

我是否遗漏了什么或者上面的代码有什么问题?

编辑 1 我在我的项目中添加了以下 Maven 依赖项

<dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-digitaltwins-core</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core-http-netty</artifactId>
            <version>1.7.1</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.49.Final</version>
        </dependency>
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty</artifactId>
            <version>1.0.7</version>
        </dependency>
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty-http</artifactId>
            <version>1.0.7</version>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-bom</artifactId>
            <version>Dysprosium-SR20</version>
            <type>pom</type>
        </dependency>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。