Azure function Java Result: Failure Exception: ClassNotFoundException

Terence Pinto 0 Reputation points
2024-07-23T16:01:00.02+00:00

I have referred to this post https://learn.microsoft.com/en-us/answers/questions/621464/azure-function-java-class-noclassdeffounderror-cou and also resolved dependency conflicts, but still get

[2024-07-23T15:43:37.521Z] Worker failed to load function: 'ServiceBusQueueTriggerJava' with functionId: '6dac0faf-7a44-47c2-8131-120704774c98'.

[2024-07-23T15:43:37.521Z] Result: Failure

Exception: ClassNotFoundException: xx.xx.xx.xx.process_topic_payment.handler.PaymentEventHandler

Stack: java.lang.ClassNotFoundException: xx.xx.xx.xxx.process_topic_payment.handler.PaymentEventHandler

[2024-07-23T15:43:37.521Z] at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)

[2024-07-23T15:43:37.521Z] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)

FUNCTIONS_WORKER_JAVA_LOAD_APP_LIBS = 1

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,085 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Pinaki Ghatak 4,610 Reputation points Microsoft Employee
    2024-07-24T09:04:45.26+00:00

    Hello @Terence Pinto

    It seems like the class xx.xx.xx.xx.process_topic_payment.handler.PaymentEventHandler is not being found by the Azure Function runtime.

    This can happen if the class is not included in the deployment package or if there are dependency conflicts.

    You mentioned that you have already resolved dependency conflicts, but have you made sure that the class is included in the deployment package?

    You can check this by verifying that the class is present in the JAR file that you are deploying.

    Also, have you set the FUNCTIONS_WORKER_JAVA_LOAD_APP_LIBS app setting to 1?

    This setting is required to load the application dependencies. If the issue persists, you can try enabling the WEBSITE_DYNAMIC_CACHE app setting to 0 to disable caching of the function app.

    This can help in cases where the runtime is not able to load the updated version of the function app.


    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.


  2. Ryan Hill 28,631 Reputation points Microsoft Employee
    2024-08-06T14:46:06.8866667+00:00

    Glad to hear your issue was resolved @Terence Pinto. To benefit the community, I'm reposting what resolved your issue so you can accept it as answered.

    You received a compiler error when running your Java function app where your ServiceBusQueueTriggerJava binding failed to load. You were able to resolve your issue by adding the extension bundle binding configuration

    {
        "version": "2.0",
        "extensionBundle": {
            "id": "Microsoft.Azure.Functions.ExtensionBundle",
            "version": "[4.0.0, 5.0.0)"
        }
    }
    

    Normally, when you create your non .NET Azure Function with available tooling, this inclusion is done for you. Make sure you have the latest Function Core Tools for your IntelliJ environment. If you continue to see to see this missing, let me know so we can create a new issue.

    0 comments No comments

  3. Terence Pinto 0 Reputation points
    2024-08-07T20:43:04.1566667+00:00

    Adding the

    <dependency>
    	<groupId>org.springframework.boot.experimental</groupId>
    	<artifactId>spring-boot-thin-layout</artifactId>
    	<version>${spring-boot-thin-layout.version}</version>
    </dependency>
    

    Fixed the issue for me

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <dependencies>
           <dependency>
              <groupId>org.springframework.boot.experimental</groupId>
              <artifactId>spring-boot-thin-layout</artifactId>
              <version>${spring-boot-thin-layout.version}</version>
           </dependency>
        </dependencies>
    </plugin>
    
    0 comments No comments

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.