gpt4 book ai didi

java - 列出 Azure 上的 SQL Server 实例

转载 作者:行者123 更新时间:2023-11-30 06:06:05 25 4
gpt4 key购买 nike

我正在尝试实现使用 Azure Java SDK 的代码列出在我的 Azure 订阅上运行的 SQL Server 实例。

我按照发布的示例编写了以下代码:

Azure azure  = Azure.authenticate(credentials)).withDefaultSubscription();
SqlServers sqlServers = azure.sqlServers();
PagedList<SqlServer> list = sqlServers.list();

但是最后一行抛出一个 java.lang.NoSuchMethodError 并带有以下堆栈跟踪:

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeBindings.create(Ljava/lang/Class;[Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/type/TypeBindings;
at com.microsoft.rest.serializer.JacksonAdapter.constructJavaType(JacksonAdapter.java:119)
at com.microsoft.rest.serializer.JacksonAdapter.deserialize(JacksonAdapter.java:131)
at com.microsoft.rest.ServiceResponseBuilder.buildBody(ServiceResponseBuilder.java:216)
at com.microsoft.rest.ServiceResponseBuilder.build(ServiceResponseBuilder.java:110)
at com.microsoft.azure.AzureResponseBuilder.build(AzureResponseBuilder.java:56)
at com.microsoft.azure.management.sql.implementation.ServersInner.listDelegate(ServersInner.java:553)
at com.microsoft.azure.management.sql.implementation.ServersInner.access$400(ServersInner.java:42)
at com.microsoft.azure.management.sql.implementation.ServersInner$17.call(ServersInner.java:539)
at com.microsoft.azure.management.sql.implementation.ServersInner$17.call(ServersInner.java:535)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:173)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.Observable.unsafeSubscribe(Observable.java:10142)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10238)
at rx.Observable.subscribe(Observable.java:10205)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:444)
at rx.observables.BlockingObservable.single(BlockingObservable.java:341)
at com.microsoft.azure.management.sql.implementation.ServersInner.list(ServersInner.java:488)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl.list(TopLevelModifiableResourcesImpl.java:116)
at AzureDiscoveryClient.main(AzureDiscoveryClient.java:19)

这显然看起来像是一个缺陷,因为 SDK 允许这样做,并且如果出现问题,应该返回一个合理的错误代码。

还有其他方法可以列出我的 Azure 订阅中运行的 SQL Server 实例吗?或者也许我正在我的代码中做一些事情?

最佳答案

请引用我的工作代码如下:

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.sql.SqlServer;
import com.microsoft.azure.management.sql.SqlServers;

import java.io.IOException;

public class ListSqlInstance {

public static void main(String[] args) throws IOException {


ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
"{client Id}",
"{talent Id}",
"{secret}",
AzureEnvironment.AZURE);
Azure.Authenticated azureAuth = Azure.authenticate(credentials);
Azure azure = azureAuth.withDefaultSubscription();

SqlServers sqlServers = azure.sqlServers();
PagedList<SqlServer> list = sqlServers.list();
System.out.println(list.size());
}
}

我的sdk版本:

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
version>1.12.0</version>
</dependency>

不要忘记向您的客户端授予访问 SQL Server 的权限。

enter image description here

希望对您有帮助。

关于java - 列出 Azure 上的 SQL Server 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51309301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com