You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Durable Functions(Java)报错:无法实例化接口

构建首个Azure Durable Functions时触发实例化异常

我在创建第一个Azure Durable Functions时遇到了错误,完全没修改过创建时生成的默认代码。

错误信息

{"name":"Cities","instanceId":"f0a50100-1556-4a82-ad2d-5b6d0f4eeed7","runtimeStatus":"Failed","input":null,"customStatus":null,"output": {"message":"Function 'Cities' failed with an unhandled exception.","details":"Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Cities\r\n ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure\nException: UnsupportedOperationException: Interface can't be instantiated! Interface name: com.microsoft.durabletask.TaskOrchestrationContext\nStack: java.lang.RuntimeException: Unable to create instance of interface com.microsoft.durabletask.TaskOrchestrationContext. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.\r\n\tat "}

我的配置文件

host.json

{
  "version": "2.0",
  "extensions": {
    "durableTask": {
        "hubName": "JavaTestHub"
    }
  },

  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

build.gradle

plugins {
    id "com.microsoft.azure.azurefunctions" version "1.12.0"
}
apply plugin: "java"

group 'com.phoenix.api'
version '1.0.0-SNAPSHOT'

dependencies {

    implementation 'com.azure:azure-identity:1.9.0'

    implementation 'com.microsoft.azure.functions:azure-functions-java-library:3.0.0'
    implementation 'com.microsoft:durabletask-azure-functions:1.1.0'
    implementation 'org.jetbrains:annotations:23.0.0'
    implementation 'com.azure:azure-storage-blob:12.22.2'

    implementation 'com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre8'


    testImplementation 'org.mockito:mockito-core:2.23.4'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
    implementation 'org.json:json:20230227'
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
}

我怀疑是缺少依赖库,但已经按要求配置了所有前置条件,请问该怎么解决?


解决方案

这个异常的核心是TaskOrchestrationContext接口无法被实例化,问题出在依赖版本不匹配或序列化配置缺失,按以下步骤处理:

  1. 对齐依赖版本

    • 当前使用的azure-functions-java-library:3.0.0和durabletask-azure-functions:1.1.0存在兼容性冲突。将两个依赖升级到匹配版本:
      implementation 'com.microsoft.azure.functions:azure-functions-java-library:3.1.0'
      implementation 'com.microsoft:durabletask-azure-functions:1.3.0'
      
  2. 补充序列化依赖

    • Durable Tasks依赖Jackson完成对象序列化,若项目未包含相关依赖,添加到build.gradle的dependencies块中:
      implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
      
  3. 验证配置文件

    • host.json中的extensionBundle版本[4.*,5.0.0)是兼容的,无需修改;确认durableTask的hubName配置无误即可。
  4. 重建项目

    • 执行./gradlew clean build清理旧构建文件,重新生成包含正确依赖的包,再重新部署或本地运行函数。

完成以上操作后,重新启动函数实例即可解决该问题。


内容的提问来源于stack exchange,提问作者SomeGuy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 13:53:22