我正在尝试使用Azure功能应用程序中的AppServiceMSICredentials API连接到CosmosDBAccount,该功能已启用为托管身份。但是身份验证部分由于ClassNotFoundException而失败。
以下是示例代码:
AppServiceMSICredentials msiCreds = new AppServiceMSICredentials(AzureEnvironment.AZURE);
Azure azure = Azure.authenticate(msiCreds).withSubscription("<subscription_id_string>”)
// get the Cosmos DB account based on the Id
CosmosDBAccount dbAccount = azure.cosmosDBAccounts().getById("<DBId>");
这是异常堆栈跟踪。任何导致此错误的原因的指针都将非常有帮助。
2019-06-18T15:51:55 Welcome, you are now connected to log-streaming service.
2019-06-18T15:52:01.435 [Information] Executing 'Functions.rotateDBKeys' (Reason='This function was programmatically called via the host APIs.', Id=32a70baf-321d-4078-b003-eebbd56d7eec)
2019-06-18T15:52:01.912 [Information] MSI Endpoints::http://127.0.0.1:41167/MSI/token/
2019-06-18T15:52:09.464 [Error] Executed 'Functions.rotateDBKeys' (Failed, Id=32a70baf-321d-4078-b003-eebbd56d7eec)
Result: Failure
Exception: ClassNotFoundException: com.microsoft.azure.ProxyResource
Stack: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
at com.microsoft.azure.functions.worker.broker.JavaMethodExecutor.execute(JavaMethodExecutor.java:54)
at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:51)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: com/microsoft/azure/ProxyResource
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at sun.misc.ProxyGenerator.generateClassFile(ProxyGenerator.java:451)
at sun.misc.ProxyGenerator.generateProxyClass(ProxyGenerator.java:339)
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:639)
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
at java.lang.reflect.WeakCache.get(WeakCache.java:127)
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
at retrofit2.Retrofit.create(Retrofit.java:133)
at com.microsoft.azure.management.batch.implementation.CertificatesInner.<init>(CertificatesInner.java:63)
at com.microsoft.azure.management.batch.implementation.BatchManagementClientImpl.initialize(BatchManagementClientImpl.java:266)
at com.microsoft.azure.management.batch.implementation.BatchManagementClientImpl.<init>(BatchManagementClientImpl.java:253)
at com.microsoft.azure.management.batch.implementation.BatchManager.<init>(BatchManager.java:31)
at com.microsoft.azure.management.batch.implementation.BatchManager.authenticate(BatchManager.java:74)
at com.microsoft.azure.management.Azure.<init>(Azure.java:414)
at com.microsoft.azure.management.Azure.<init>(Azure.java:129)
at com.microsoft.azure.management.Azure$AuthenticatedImpl.withSubscription(Azure.java:390)
at com.microsoft.azure.azure_functions_archetype.Function.rotateDBKeys(Function.java:37)
... 16 more
Caused by: java.lang.ClassNotFoundException: com.microsoft.azure.ProxyResource
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 50 more