microsoft / microsoft/azure-tools-for-java

Unable to execute Spring Azure Function via Azure Toolkit Plugin

Open
#7,849 0 comments 0 reactions 1 assignee View on GitHub

@Flanker32 is already working on this.

Since Sep 19, 2023.

Module: Azure Functions
Dominant language
Java
Stars
262
Forks
185
Avg merge
2d 21h
Merged PRs (30d)
1

Description

IntelliJ build version: 2023.2.1 IC-232.9559.62
OS: Windows 11
JDK: JetBrains s.r.o. 17.0.8
Plugin version: 3.80.2-2023.2
Additional Info: None

When I try to execute a Spring Azure function :

https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-azure-http-trigger

I keep getting the exception whenever I hit any in the function app http://localhost:7071/api/bean

[2023-09-13T12:59:34.868Z] System.Private.CoreLib: Exception while executing function: Functions.bean. System.Private.CoreLib: Result: Failure
Exception: IllegalArgumentException: Failed to locate main class
Stack: java.lang.IllegalStateException: Failed to initialize
[2023-09-13T12:59:34.868Z] 	at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.getInstance(AzureFunctionInstanceInjector.java:80)
[2023-09-13T12:59:34.868Z] 	at com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource.getFunctionInstance(ExecutionContextDataSource.java:103)
[2023-09-13T12:59:34.869Z] 	at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:20)
[2023-09-13T12:59:34.869Z] 	at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:22)
[2023-09-13T12:59:34.869Z] 	at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
[2023-09-13T12:59:34.870Z] 	at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2023-09-13T12:59:34.870Z] 	at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:125)
[2023-09-13T12:59:34.870Z] 	at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
[2023-09-13T12:59:34.870Z] 	at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2023-09-13T12:59:34.871Z] 	at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2023-09-13T12:59:34.871Z] 	at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
[2023-09-13T12:59:34.871Z] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[2023-09-13T12:59:34.872Z] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2023-09-13T12:59:34.872Z] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[2023-09-13T12:59:34.872Z] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[2023-09-13T12:59:34.872Z] 	at java.base/java.lang.Thread.run(Thread.java:833)
[2023-09-13T12:59:34.873Z] Caused by: 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).
[2023-09-13T12:59:34.873Z] 	at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:86)
[2023-09-13T12:59:34.873Z] 	at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:63)
[2023-09-13T12:59:34.873Z] 	at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.initialize(AzureFunctionInstanceInjector.java:90)
[2023-09-13T12:59:34.874Z] 	at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.getInstance(AzureFunctionInstanceInjector.java:66)
[2023-09-13T12:59:34.874Z] 	... 15 more
[2023-09-13T12:59:34.874Z] Caused by: java.lang.IllegalArgumentException: Failed to locate main class
[2023-09-13T12:59:34.874Z] 	at org.springframework.util.Assert.notNull(Assert.java:172)
[2023-09-13T12:59:34.875Z] 	at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:82)
[2023-09-13T12:59:34.875Z] 	... 18 more
[2023-09-13T12:59:34.875Z] .

This error is only specific when running a Spring Azure Function from the IntelliJ Plugin.

It does not happen when running it from Maven:

mvnw azure-functions:run

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.