Thursday, 15 August 2019

spring cloud function -- azure function

After  you fixed the issue in the office sample app, https://baiduhix.blogspot.com/2019/08/systemprivatecorelib-exception-while.html

Then you may still have issue, if you create a new project:

spring boot should run ok, but not azure function

after you run "mvn azure-functions:run"

if you call it by: "curl -H "Content-Type: application/json" -i http://localhost:7071/api/uppercase -d '{"value": "hello world"}'"

you may get "HTTP/1.1 500 Internal Server Error"

and your code return:


[14/08/2019 16:13:26] Executed 'Functions.uppercase' (Failed, Id=26846fed-35b6-41cf-ad31-e796672a1721)
[14/08/2019 16:13:26] System.Private.CoreLib: Exception while executing function: Functions.uppercase. System.Private.CoreLib: Result: Failure
[14/08/2019 16:13:26] Exception: IllegalStateException: No function defined with name=uppercase
[14/08/2019 16:13:26] Stack: java.lang.reflect.InvocationTargetException
[14/08/2019 16:13:26] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[14/08/2019 16:13:26] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[14/08/2019 16:13:26] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[14/08/2019 16:13:26] at java.lang.reflect.Method.invoke(Method.java:498)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.broker.JavaMethodExecutor.execute(JavaMethodExecutor.java:54)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:51)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[14/08/2019 16:13:26] at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[14/08/2019 16:13:26] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[14/08/2019 16:13:26] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[14/08/2019 16:13:26] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[14/08/2019 16:13:26] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[14/08/2019 16:13:26] at java.lang.Thread.run(Thread.java:748)
[14/08/2019 16:13:26] Caused by: java.lang.IllegalStateException: No function defined with name=uppercase
[14/08/2019 16:13:26] at org.springframework.cloud.function.adapter.azure.AzureSpringFunctionInitializer.lookup(AzureSpringFunctionInitializer.java:174)
[14/08/2019 16:13:26] at org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler.handleRequest(AzureSpringBootRequestHandler.java:54)
[14/08/2019 16:13:26] at com.xxx.FooHandler.execute(FooHandler.java:26)
[14/08/2019 16:13:26] ... 16 more

[14/08/2019 16:13:26] .



from the error you can see it can call your azure function successfully, just not able to find the function -- uppersase, it is because we haven't registory it as a function.

then you need to make sure in your pom file, in the maven-jar-plugin, you need to change the path to your spring boot main class:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>example.xx.Config</mainClass>
      </manifest>
    </archive>
  </configuration>
</plugin>



start-class in properties is useless:


<start-class>com.mns.foods.fist.Config</start-class>


4 comments: