Open
Description
Using spring-cloud-function 4.2.2 and spring-boot 3.4.6, it seems that we cannot run a SpringBoot app compiled with AOT on an Azure function.
The issue seems to come from the FunctionalSpringApplication: when trying to deduce the main class (using SpringApplication#findMainClass), the stack does not contain the class hence it's resolved as null
.
Later on, when the SpringBoot's EnvironmentPostProcessorApplicationListener
kicks in, it tries to add post-processors in addAotGeneratedEnvironmentPostProcessorIfNecessary based on the application's main class. Since it's been resolved as null
the execution results in a NullPointerException.
Created a dummy example here: https://github.com/nekhtan/spring-azfun-aot
[2025-06-03T10:17:35.760Z] 12:17:35.760 [pool-2-thread-1] INFO org.springframework.cloud.function.utils.FunctionClassUtils -- Loaded Start Class: class com.azfun.aot.Application
[2025-06-03T10:17:35.760Z] 12:17:35.760 [pool-2-thread-1] INFO org.springframework.cloud.function.utils.FunctionClassUtils -- Main class: class com.azfun.aot.Application
[2025-06-03T10:17:35.760Z] 12:17:35.760 [pool-2-thread-1] INFO org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector -- Initializing: class com.azfun.aot.Application
[2025-06-03T10:17:35.826Z] 12:17:35.826 [pool-2-thread-1] ERROR org.springframework.boot.SpringApplication -- Application run failed
[2025-06-03T10:17:35.826Z] java.lang.NullPointerException: Cannot invoke "java.lang.Class.getName()" because the return value of "org.springframework.boot.SpringApplication.getMainApplicationClass()" is null
[2025-06-03T10:17:35.827Z] at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.addAotGeneratedEnvironmentPostProcessorIfNecessary(EnvironmentPostProcessorApplicationListener.java:160)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:130)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:115)
[2025-06-03T10:17:35.827Z] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
[2025-06-03T10:17:35.827Z] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
[2025-06-03T10:17:35.827Z] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
[2025-06-03T10:17:35.827Z] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
[2025-06-03T10:17:35.827Z] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
[2025-06-03T10:17:35.827Z] at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
[2025-06-03T10:17:35.827Z] at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.initialize(AzureFunctionInstanceInjector.java:99)
[2025-06-03T10:17:35.827Z] at org.springframework.cloud.function.adapter.azure.AzureFunctionInstanceInjector.getInstance(AzureFunctionInstanceInjector.java:70)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource.getFunctionInstance(ExecutionContextDataSource.java:103)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:20)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:22)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:125)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2025-06-03T10:17:35.827Z] at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
[2025-06-03T10:17:35.827Z] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
[2025-06-03T10:17:35.827Z] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
[2025-06-03T10:17:35.827Z] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[2025-06-03T10:17:35.827Z] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[2025-06-03T10:17:35.827Z] at java.base/java.lang.Thread.run(Thread.java:1583)
Metadata
Metadata
Assignees
Labels
No labels