【发布时间】:2019-03-19 14:08:55
【问题描述】:
我试图弄清楚如何使用 Java 和一个简单的温度转换函数来创建 Azure Functions。我试图定义的路线是:
temps/{method}/{temp?}
我已经修改了为新 Java 项目生成的模板化 HttpTrigger 代码:
@FunctionName("temps")
public HttpResponseMessage run(
@HttpTrigger(name = "req",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS,
route = "temps/{method}/{temp:float?}")
HttpRequestMessage<Optional<String>> request,
@BindingName("method") String method,
@BindingName("temp") String temp,
final ExecutionContext context) {...}
当我实际将温度值作为最后一个参数传递时,它工作正常,但如果我只是调用“temps/{method}”,我会在
处得到 NullPointerException
com.microsoft.azure.functions.worker.binding.BindingDataStore.getTriggerMetatDataByName(BindingDataStore.java:54).
所以我假设我没有正确定义绑定,以便当最后一个参数不包含在 URI 中时它可以正确处理。我看过许多其他关于此的帖子,其中包括“?”应该工作,所以想知道我是否遗漏了一些明显的东西。注意:我有代码来测试在 temp 中传递的值是否是浮点值,所以可以正常工作。
【问题讨论】:
标签: java azure azure-functions