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

本地运行Java版Azure Functions Blob Trigger报错:未找到Java函数

Java版Azure Functions Blob Trigger本地启动报错排查

本地运行Java编写的Azure Functions Blob Trigger,已安装Core Tools并完成host.json、local.settings.json配置,但启动时提示“未找到Java语言的函数”,相关代码、配置及错误日志如下:

函数类代码

public class BlobTrigger {
/**
* This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.
*/
@FunctionName("BlobTriggerJava")
@StorageAccount("AzureWebJobsStorage")
public void process(
@BlobTrigger(name = "BlobTrigger", path = "mycontainer/{name}", dataType = "binary") String content,
@BindingName("name") String filename,
final ExecutionContext context
) {
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + filename + "\n  Size: " + content.length() + " Bytes");
}
}

host.json

{
      "version": "2.0",
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[2.*, 3.0.0)"
      },
    }

local.settings.json

{
      "IsEncrypted": false,
      "Values": {
        "FUNCTIONS_WORKER_RUNTIME": "java",
        "AzureWebJobsStorage": "yuyoiuu",
        "JAVA_HOME": "C:\\Program Files\\Java\\jdk-11\\bin\\java.exe"
      }
    }

错误日志

[2024-09-25T14:01:16.007Z] A host error has occurred during startup operation 'd5fc1da7-0896-422d-b0fb-4b7156b7cf44'.
[2024-09-25T14:01:16.007Z] Microsoft.Azure.WebJobs.Script: Did not find functions with language [java].
[2024-09-25T14:01:16.017Z] Failed to stop host instance 'b6edcdeb-bf79-45ac-87fa-ee90fd5a0549'.
[2024-09-25T14:01:16.017Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2024-09-25T14:01:16.051Z] A host error has occurred during startup operation '24fd6af8-c37c-4ba0-9325-77bbdba9b29b'.
[2024-09-25T14:01:16.051Z] Microsoft.Extensions.DependencyInjection: Cannot access a disposed object.
[2024-09-25T14:01:16.051Z] Object name: 'IServiceProvider'.
Function execute succeed.

修复步骤

  1. 修正JAVA_HOME配置
    local.settings.json中的JAVA_HOME指向了java.exe可执行文件,需改为JDK根目录:

    "JAVA_HOME": "C:\\Program Files\\Java\\jdk-11"
    
  2. 修复AzureWebJobsStorage值
    当前配置的"yuyoiuu"为无效值,本地开发可使用存储模拟器:

    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
    

    或替换为有效的Azure存储账户连接字符串。

  3. 调整BlobTrigger参数类型匹配
    代码中dataType="binary"对应参数类型应为byte[]而非String,若需读取字符串内容,修改为:

    @BlobTrigger(name = "BlobTrigger", path = "mycontainer/{name}", dataType = "string") String content
    
  4. 确认函数编译与启动路径

    • 先执行mvn clean package编译项目,生成的jar包会放在target/azure-functions/<函数应用名>目录下
    • 切换到该目录后再执行func start,或通过func start --working-dir <目标路径>指定工作目录
  5. 验证依赖与版本兼容性

    • 确保pom.xml中已引入azure-functions-java-library依赖
    • Core Tools版本需支持Java 11(推荐v4.x),Java版本使用Azure Functions支持的LTS版本(8、11、17)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 01:37:30