[英]Java based Azure Function - Exception: ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast
I'm newbie with Java.我是 Java 新手。 I have created most simple Http Triggered Azure Function with Visual Studio Code.我使用 Visual Studio Code 创建了最简单的 Http Triggered Azure 函数。 Code is default from template and unmodifed.代码是模板的默认值且未修改。 However when I get error when calling http://localhost:7071/api/HttpExample但是,当我在调用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)
Judging by the presence of java.base/jdk.internal.loader.ClassLoaders in the stack trace, you are using Java 9 or later.根据堆栈跟踪中 java.base/jdk.internal.loader.ClassLoaders 的存在判断,您使用的是 Java 9 或更高版本。 Spring Boot's DefaultRestartInitializer is trying to cast the app class loader to a URLClassLoader. Spring Boot 的 DefaultRestartInitializer 试图将应用程序类加载器转换为 URLClassLoader。 This works in Java 8 and earlier but does not work with Java 9 or later.这适用于 Java 8 及更早版本,但不适用于 Java 9 或更高版本。 Spring Boot had been updated in 2.0 to cope with this change in Java 9. Spring Boot 已在 2.0 中更新以应对 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.如果要在 Java 9 或更高版本中使用 Spring Boot,则应升级到 Spring Boot 2。在撰写本文时,最新版本是 2.0.5,支持 Java 8、9 和 10。Spring Boot 2.1,它将今年晚些时候发布,将增加对 Java 11 的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.