Spring Boot app fails on Azure function App

PS 20 Reputation points
2025-02-04T14:22:28.2366667+00:00

I am trying to deploy vanilla I am following below doc :

https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/getting-started-with-spring-cloud-function-in-azure

on local with maven run work perfectly fine

mvn azure-functions:run -DenableDebug   

on function app deployment there is no error. but when I run the api I get below error.

I have main class defined in pom.xml, same get generated into fat jar meta-inf and I also have tried adding environment variable MAIN_CLASS

Result: Failure

Exception: IllegalArgumentException: Failed to locate main class

Stack: java.lang.IllegalStateException: Failed to initialize
at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.getInstance(AzureFunctionInstanceInjector.java:84)
at com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource.getFunctionInstance(ExecutionContextDataSource.java:103)
at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:20)
at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:22)
at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:125)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
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).
scala
at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:86)
at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:63)
at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.initialize(AzureFunctionInstanceInjector.java:97)
at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.getInstance(AzureFunctionInstanceInjector.java:70)
... 15 more
Caused by: java.lang.IllegalArgumentException: Failed to locate main class
scala
at org.springframework.util.Assert.notNull(Assert.java:181)
at org.springframework.cloud.function.utils.FunctionClassUtils.getStartClass(FunctionClassUtils.java:82)
... 18 more
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shireesha Eeraboina 3,435 Reputation points Microsoft External Staff Moderator
    2025-02-05T07:28:20.7066667+00:00

    Hi @PS,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    It looks like you're encountering an issue with deploying your Spring Cloud Function to Azure Functions, specifically related to the main class not being found. Here’s a simplified approach to troubleshoot and resolve the problem:

    • Make sure that the main class is properly specified in your pom.xml. This is essential for Azure Functions to identify which class should be executed.
    • If you've configured the MAIN_CLASS environment variable, verify that it corresponds to the fully qualified name of your main class.
    • Ensure that your Azure Functions configuration files (such as host.json and local.settings.json) are properly configured and align with the requirements of your application.
    • Utilize the Azure portal to review the logs for your Function App. This can offer valuable insights into any issues that may arise when the API is invoked.
    • Make sure that all required dependencies are included in your pom.xml and that there are no version conflicts.

    Also, for your better understanding, please refer to the following documentation:

    https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/getting-started-with-spring-cloud-function-in-azure

    By following these steps, you should be able to resolve the "Failed to locate main class" error and successfully run your Spring Cloud Function in Azure. If you continue to experience issues, please provide any additional error messages or context for further assistance.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.