服务或财产未注册错误

时间:2021-07-23 15:23:29

Simply when I run this code:

只需在我运行此代码时:

Configuration azureConfig = ManagementConfiguration.configure(
    new URI("https://management.core.windows.net/"), 
    "asdasdasd",
    "server.keystore",
    "asdasdasd",
    KeyStoreType.jks
);
ManagementClient client = ManagementService.create(azureConfig);
LocationsListResponse response = client.getLocationsOperations().list();
ArrayList locations = response.getLocations();

for( int i=0; i<locations.size(); i++){
    System.out.println(((LocationsListResponse.Location)locations.get(i)).getDisplayName());
}

I get this:

我明白了:

00:52:04 [SEVERE] java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.management.ManagementClient interface com.microsoft.windowsazure.management.ManagementClient
00:52:04 [SEVERE]     at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:197)
00:52:04 [SEVERE]     at com.microsoft.windowsazure.Configuration.create(Configuration.java:113)
00:52:04 [SEVERE]     at com.microsoft.windowsazure.management.ManagementService.create(ManagementService.java:46)
00:52:04 [SEVERE]     at {LINE OF CODE THAT CONTAINS ManagementClient client = ManagementService.create(azureConfig);}

On internet there's only 1 question about this, about Android and don't has a clear reply... Has someone solved this problem?

在互联网上只有一个问题,关于Android,并没有一个明确的答复...有人解决了这个问题?

I run it under OpenLogic 6.5 (based on CentOS) in a Virtual Machine from Azure with Java 1.8.

我在Azure和Java 1.8的虚拟机中使用OpenLogic 6.5(基于CentOS)运行它。

EDIT: I created a new project and launched it from eclipse. I get the correct results but when I launch it from command line (java -jar test.jar) i receive exactly the same error.

编辑:我创建了一个新项目并从eclipse启动它。我得到了正确的结果但是当我从命令行(java -jar test.jar)启动它时,我收到完全相同的错误。

1 个解决方案

#1


1  

I also faced similar issue. Explicitly setting context class loader solved the problem

我也遇到过类似的问题。显式设置上下文类加载器解决了这个问题

// Get current context class loader
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); 
// Change context classloader to class context loader   
Thread.currentThread().setContextClassLoader(AzureManagementServiceDelegate.class.getClassLoader)); 
try { 
     // Call Azure API and reset back the context loader 
} catch (Exception e) {
    // handle exceptions  
} finally {
 // Reset back class loader
Thread.currentThread().setContextClassLoader(contextLoader); 
}

#1


1  

I also faced similar issue. Explicitly setting context class loader solved the problem

我也遇到过类似的问题。显式设置上下文类加载器解决了这个问题

// Get current context class loader
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); 
// Change context classloader to class context loader   
Thread.currentThread().setContextClassLoader(AzureManagementServiceDelegate.class.getClassLoader)); 
try { 
     // Call Azure API and reset back the context loader 
} catch (Exception e) {
    // handle exceptions  
} finally {
 // Reset back class loader
Thread.currentThread().setContextClassLoader(contextLoader); 
}