作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写代码以在 Eclipse 中创建 Amazon Web Services SNS 客户端,当我收到错误消息
The method withRegion(Region) from the type AwsClientBuilder is not visible
这是我的代码
package com.amazonaws.samples;
import java.util.Date;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.CreateTopicRequest;
import com.amazonaws.services.sns.model.CreateTopicResult;
import com.amazonaws.services.sns.model.PublishRequest;
// Example SNS Sender
public class Main {
// AWS credentials -- replace with your credentials
static String ACCESS_KEY = "<Your AWS Access Key>";
static String SECRET_KEY = "<Your AWS Secret Key>";
// Sender loop
public static void main(String... args) throws Exception {
// Create a client
AWSCredentials awsCred = new AnonymousAWSCredentials();
AWSStaticCredentialsProvider cred = new AWSStaticCredentialsProvider(awsCred);
Region region = Region.getRegion(Regions.US_EAST_1);
AmazonSNS service = AmazonSNSClientBuilder.standard().withRegion(region).withCredentials(cred).build(); // Error message: The method withRegion(Region) from the type AwsClientBuilder<AmazonSNSClientBuilder,AmazonSNS> is not visible
// Create a topic
CreateTopicRequest createReq = new CreateTopicRequest()
.withName("MyTopic3");
CreateTopicResult createRes = service.createTopic(createReq);
for (;;) {
// Publish to a topic
PublishRequest publishReq = new PublishRequest()
.withTopicArn(createRes.getTopicArn())
.withMessage("Example notification sent at " + new Date());
service.publish(publishReq);
Thread.sleep(1000);
}
}
}
在屏幕截图中,它显示了错误发生的位置,并用虚线显示了红色下划线:
我应该检查什么来纠正这个问题?
最佳答案
您传递了错误的参数,withRegion
采用 String
或 Regions
(注意,不是 Region
>,单数)。
尝试传递Regions.EU_WEST_1
。
两者AmazonSNSClientBuilder.standard().withRegion(Regions.EU_WEST_1).build();
和AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();
对我来说工作得很好。
关于java - 为什么 AmazonSNSClientBuilder 的 withRegion() 不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56277899/
我正在编写代码以在 Eclipse 中创建 Amazon Web Services SNS 客户端,当我收到错误消息 The method withRegion(Region) from the ty
我是一名优秀的程序员,十分优秀!