Java Azure中的Spring云函数在触发时抛出IllegalStateException

Java Azure中的Spring云函数在触发时抛出IllegalStateException,java,spring,azure,azure-functions,Java,Spring,Azure,Azure Functions,运行azure函数:使用mvn运行目标后,我在端点上触发azure函数: 你好:[获取,发布]http://localhost:7071/api/hello 在日志中显示Spring启动了,我得到了以下错误,我无法理解其原因: [2020-11-10T10:56:35.253Z] Handler processing a request for: hello [2020-11-10T10:56:35.272Z] Executed 'Functions.hello' (Failed, Id=403

运行azure函数:使用mvn运行目标后,我在端点上触发azure函数:

你好:[获取,发布]http://localhost:7071/api/hello

在日志中显示Spring启动了,我得到了以下错误,我无法理解其原因:

[2020-11-10T10:56:35.253Z] Handler processing a request for: hello
[2020-11-10T10:56:35.272Z] Executed 'Functions.hello' (Failed, Id=403ee5e4-464b-4d0a-bd56-d6ade21d2de8, Duration=1103ms)
[2020-11-10T10:56:35.272Z] System.Private.CoreLib: Exception while executing function: Functions.hello. System.Private.CoreLib: Result: Failure
[2020-11-10T10:56:35.272Z] Exception: IllegalStateException: No function defined
[2020-11-10T10:56:35.272Z] Stack: java.lang.reflect.InvocationTargetException
[2020-11-10T10:56:35.272Z]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2020-11-10T10:56:35.272Z]  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[2020-11-10T10:56:35.272Z]  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2020-11-10T10:56:35.272Z]  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:55)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:57)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2020-11-10T10:56:35.272Z]  at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2020-11-10T10:56:35.272Z]  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2020-11-10T10:56:35.272Z]  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2020-11-10T10:56:35.272Z]  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2020-11-10T10:56:35.272Z]  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2020-11-10T10:56:35.272Z]  at java.base/java.lang.Thread.run(Thread.java:834)
[2020-11-10T10:56:35.272Z] Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalStateException: No function defined
[2020-11-10T10:56:35.272Z]  at org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler.handleRequest(AzureSpringBootRequestHandler.java:99)
[2020-11-10T10:56:35.272Z]  at com.dropware.function.HelloHandler.execute(HelloHandler.java:28)
[2020-11-10T10:56:35.272Z]  ... 16 more
[2020-11-10T10:56:35.272Z] Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: No function defined
[2020-11-10T10:56:35.272Z]  at org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler.handleRequest(AzureSpringBootRequestHandler.java:99)
[2020-11-10T10:56:35.272Z]  at org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler.handleRequest(AzureSpringBootRequestHandler.java:83)
[2020-11-10T10:56:35.272Z]  ... 17 more
[2020-11-10T10:56:35.272Z] Caused by: java.lang.IllegalStateException: No function defined
我有两个域类:

公开课问候语{ 公众问候{ } 公共问候字符串消息{ this.message=消息; } 私有字符串消息; 公共字符串getMessage{ 返回消息; } 公共void setMessageString消息{ this.message=消息; } } 公共类用户{ 公共用户{ } 公共用户字符串名称{ this.name=名称; } 私有字符串名称; 公共字符串getName{ 返回名称; } public void setNameString名称{ this.name=名称; } } 该函数是HTTP触发的,它完全遵循提供的示例

公共类HelloHandler扩展AzureSpringBootRequestHandler{ @函数名你好 公共httpresponsemessageexecute @HttpTriggername=request,methods={HttpMethod.GET,HttpMethod.POST}, authLevel=AuthorizationLevel.ANONYMOUS HttpRequestMessage请求, ExecutionContext上下文{ context.getLogger.infoGreeting用户名:+request.getBody.get.getName; 退货申请 .createResponseBuilderHttpStatus.OK .BodyHandlerRequestRequest.getBody.get,上下文 .headerContent类型,应用程序/json 建筑 } } Spring的入口点是最直接的

@SpringBoot应用程序 公共类应用程序{ 公共静态无效主字符串[]args引发异常{ SpringApplication.runApplication.class,args; } @豆子 公共功能你好{ return user->new GreetingWelcome,+user.getName; } } pom.xml文件中的依赖项包括:

    org.junit.jupiter
    junit-jupiter
    5.4.2
        
    org.mockito</groupId>
    mockito-core
    2.23.4

    org.springframework.boot
    spring-boot-starter-test
    2.3.5.RELEASE

    com.microsoft.azure.functions
    azure-functions-java-library
    1.3.1

    org.springframework.cloud
    spring-cloud-function-adapter-azure
    3.0.11.RELEASE
        
    org.springframework.cloud
    spring-cloud-function-web
    3.0.11.RELEASE
        
    org.springframework.boot
    spring-boot-starter-jdbc
    2.3.5.RELEASE
        
    org.springframework.boot
    spring-boot-devtools
    2.3.5.RELEASE
       
    org.springframework.boot
    spring-boot-configuration-processor
    2.3.4.RELEASE
        
    mysql
    mysql-connector-java
    8.0.22

请参阅下面的pom.xml,并确保没有遗漏任何字段和应用程序设置


    <property>
      <name>WEBSITE_RUN_FROM_PACKAGE</name>
      <value>1</value>
    </property>
    <property>
      <name>FUNCTIONS_EXTENSION_VERSION</name>
      <value>~3</value>
    </property>
    <property>
      <name>FUNCTIONS_WORKER_RUNTIME</name>
      <value>java</value>
    </property>  

                        

虽然这段代码可以回答这个问题,但提供关于它如何和/或为什么解决问题的附加上下文将提高答案的长期价值。
@Bean("hello")
    public Function<User, Greeting> hello() {
        return user -> new Greeting("Welcome, " + user.getName());
    }

@Bean("GoodMorning")
    public Function<User, Greeting> goodMorning() {
        return user -> new Greeting("Good Morning " + user.getName());
    }



    <property>
      <name>WEBSITE_RUN_FROM_PACKAGE</name>
      <value>1</value>
    </property>
    <property>
      <name>FUNCTIONS_EXTENSION_VERSION</name>
      <value>~3</value>
    </property>
    <property>
      <name>FUNCTIONS_WORKER_RUNTIME</name>
      <value>java</value>
    </property>