0
我正在使用AWS開發工具包for Java在AWS計量服務中使用。當我試圖用AWSMarketplaceMeteringClientBuilder
創建AWSMarketplaceMeteringClient
,我發現,如果我用withRegion(Region region)
方法,我得到以下編譯時錯誤:AWSMarketplaceMeteringClientBuilder.withRegion()不可見
The method withRegion(Region) from the type AwsClientBuilder<AWSMarketplaceMeteringClientBuilder,AWSMarketplaceMetering> is not visible
如下圖所示的客戶端代碼:
AWSMarketplaceMeteringClient metClient = (AWSMarketplaceMeteringClient) AWSMarketplaceMeteringClientBuilder
.standard()
.withRegion(Regions.getCurrentRegion())
.withCredentials(InstanceProfileCredentialsProvider.getInstance())
.build();
而且當我嘗試使用AWSMarketplaceMeteringClient
直接setRegion(Region region)
方法,我得到以下運行時錯誤:
Exception in thread "main" java.lang.UnsupportedOperationException: Client is immutable when created with the builder.
at com.amazonaws.AmazonWebServiceClient.checkMutability(AmazonWebServiceClient.java:854)
at com.amazonaws.AmazonWebServiceClient.setRegion(AmazonWebServiceClient.java:349)
那麼應該如何使用withRegion(Region region)方法?