0

I'm newbie with Java. I have created most simple Http Triggered Azure Function with Visual Studio Code. Code is default from template and unmodifed. However when I get error when calling http://localhost:7071/api/HttpExample

What could be issue and fix?

Http Functions:

    HttpExample: [GET,POST] http://localhost:7071/api/HttpExample

[14.3.2020 11.36.30] Host lock lease acquired by instance ID '0000000000000000000000008457DB20'.
[14.3.2020 11.38.23] Executing HTTP request: {
[14.3.2020 11.38.23]   "requestId": "22ff78da-8114-4dfe-a76e-ad2c3f2d9e99",
[14.3.2020 11.38.23]   "method": "GET",
[14.3.2020 11.38.23]   "uri": "/api/HttpExample"
[14.3.2020 11.38.23] }
[14.3.2020 11.38.23] Executing 'Functions.HttpExample' (Reason='This function was programmatically 
called via the host APIs.', Id=137d2055-2fbf-4eba-bbb7-fe6167aae5db)
[14.3.2020 11.38.23] Executed 'Functions.HttpExample' (Failed, Id=137d2055-2fbf-4eba-bbb7- 
fe6167aae5db)
[14.3.2020 11.38.23] System.Private.CoreLib: Exception while executing function: 
Functions.HttpExample. System.Private.CoreLib: Result: Failure      
Exception: ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast 
to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and 
java.net.URLClassLoader are in module java.base of loader 'bootstrap')
Stack: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be 
cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and 
java.net.URLClassLoader are in module java.base of loader 'bootstrap')
[14.3.2020 11.38.23]    at com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider.addUrlToSystemClassLoader(Default 
   ClassLoaderProvider.java:72)

enter image description here

1
  • what's your java version ?Currently Azure Functions only support Java 8 Commented Mar 16, 2020 at 7:25

1 Answer 1

1

Judging by the presence of java.base/jdk.internal.loader.ClassLoaders in the stack trace, you are using Java 9 or later. Spring Boot's DefaultRestartInitializer is trying to cast the app class loader to a URLClassLoader. This works in Java 8 and earlier but does not work with Java 9 or later. Spring Boot had been updated in 2.0 to cope with this change in Java 9.

If you want to use Spring Boot with Java 9 or later, you should upgrade to Spring Boot 2. At the time of writing, the latest release is 2.0.5 which supports Java 8, 9, and 10. Spring Boot 2.1, which will be released later this year, will add support for Java 11.

Sign up to request clarification or add additional context in comments.

2 Comments

I have never installed Spring Boot to my PC. Did it came with VS Code? What is simplest way of get simple Java code to work with VS Code? Any link?
I removed Java 11 and installed Java 8. It works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.