2

尝试运行azure-sample,但在请求进入时遇到“无法定位主类”错误。

使用 Maven 在 Eclipse 中构建项目。基于此问题更新代码(否则您将获得 ClassCast 异常)。

在本地或远程(部署后)运行会产生相同的错误。

没有更改示例中的 POM,只是指向我的 functionAppName、Region、ResourceGroup 以准备部署。

Executed 'Functions.uppercase' (Failed, Id=349ca69e-4548-4af2-b6a4-84bf5afbedb5)
[4/10/19 9:03:39 PM] System.Private.CoreLib: Exception while executing function: Functions.uppercase. System.Private.CoreLib: Result: Failure
[4/10/19 9:03:39 PM] Exception: IllegalArgumentException: Failed to locate main class
[4/10/19 9:03:39 PM] Stack: java.lang.IllegalStateException: Failed to discover main class. An attempt was made to discover main class as 'MAIN_CLASS' environment variable, system property as well as entry in META-INF/MANIFEST.MF (in that order).
[4/10/19 9:03:39 PM]    at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.getStartClass(AbstractSpringFunctionAdapterInitializer.java:279)
[4/10/19 9:03:39 PM]    at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.<init>(AbstractSpringFunctionAdapterInitializer.java:99)
[4/10/19 9:03:39 PM]    at org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler.<init>(AzureSpringBootRequestHandler.java:44)
[4/10/19 9:03:39 PM]    at example.FooHandler.<init>(FooHandler.java:33)
[4/10/19 9:03:39 PM]    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[4/10/19 9:03:39 PM]    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[4/10/19 9:03:39 PM]    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[4/10/19 9:03:39 PM]    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[4/10/19 9:03:39 PM]    at java.lang.Class.newInstance(Class.java:442)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.broker.JavaMethodExecutor.lambda$execute$1(JavaMethodExecutor.java:54)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:20)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.broker.JavaMethodExecutor.execute(JavaMethodExecutor.java:54)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:51)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[4/10/19 9:03:39 PM]    at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[4/10/19 9:03:39 PM]    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[4/10/19 9:03:39 PM]    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[4/10/19 9:03:39 PM]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[4/10/19 9:03:39 PM]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[4/10/19 9:03:39 PM]    at java.lang.Thread.run(Thread.java:748)
[4/10/19 9:03:39 PM] Caused by: java.lang.IllegalArgumentException: Failed to locate main class
[4/10/19 9:03:39 PM]    at org.springframework.util.Assert.notNull(Assert.java:198)
[4/10/19 9:03:39 PM]    at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.getStartClass(AbstractSpringFunctionAdapterInitializer.java:275)
[4/10/19 9:03:39 PM]    ... 21 more

编辑: azure-functions 文件夹中的 jar 似乎与 Thin spring maven 插件创建的最终 jar 不同。清单文件包含不同的电源。azure-functions jar 似乎只是 maven-jar-plugin 的结果,但它仍然引用 @SpringBootApplication 类作为它的主要类。这不应该仍然有效吗?在这个例子中使用瘦包装器有什么意义?

4

1 回答 1

3

目前,这可以通过将 spring-cloud-function-dependencies 版本更改为 2.0.1.RELEASE 来解决

另外值得注意的是,任何 application.properties 都应在构建后放入 azure-functions 文件夹。这可以通过多种方式完成。

于 2019-04-10T22:21:54.343 回答