【问题标题】:Azure Function with Spring Boot + Spring Cloud Function unable to locate main class带有 Spring Boot + Spring Cloud Function 的 Azure Function 无法找到主类
【发布时间】:2019-04-10 21:10:20
【问题描述】:

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

在 Eclipse 中使用 maven 构建项目。更新了基于this issue 的代码(否则您将获得 ClassCast 异常)。

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

除了指向我的函数AppName、Region、ResourceGroup 以准备部署之外,没有更改示例中的 POM。

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 类作为它的主要类。这不应该仍然有效吗?在这个例子中使用瘦包装器有什么意义?

【问题讨论】:

    标签: spring-boot azure-functions azure-eventhub spring-cloud-function


    【解决方案1】:

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

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

    【讨论】:

    • 你也可以升级到2.1.1吗?有一些与此相关的变化
    猜你喜欢
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2018-10-16
    • 2021-04-02
    • 2021-12-18
    • 2020-05-31
    相关资源
    最近更新 更多