java - 线程 "main"java.lang.NoSuchFieldError : INSTANCE in AWS SNS 中出现异常

标签 java amazon-web-services sms

我正在尝试通过 Amazon Web 服务发送短信。我已经下载了SD
封装com.sms;

import java.util.HashMap;
import java.util.Map;

import com.sms.AwsClientFactoryDemo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.services.sns.model.MessageAttributeValue;
import com.amazonaws.services.sns.model.PublishRequest;
import com.amazonaws.services.sns.model.PublishResult;

public class SmsNotificationService {
    private static final Logger LOG = LoggerFactory.getLogger(SmsNotificationService.class);

    public PublishResult send(String phoneNumber, String message) {
        Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>();
        smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
                .withStringValue("Lightside") //The sender ID shown on the device (except in US)
                .withDataType("String"));
        smsAttributes.put("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue()
                .withStringValue("0.01") //Sets the max price to 0.01 USD.
                .withDataType("Number"));
        smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
                .withStringValue("Promotional") //Sets the type to promotional.
                .withDataType("String"));
        PublishResult result = AwsClientFactoryDemo.getSnsClient().publish(new PublishRequest()
                .withMessage(message)
                .withPhoneNumber(phoneNumber)
                .withMessageAttributes(smsAttributes));
        LOG.info("Sent SMS message ID: " + result.getMessageId());
        return result;
    }

}

在尝试通过 aws sns 发送短信时,我在上述代码中遇到以下错误。

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:87)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:65)
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:58)
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:51)
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:39)
    at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:300)
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:164)
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:153)
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:207)
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:187)
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:97)
    at com.sms.sms.main(sms.java:13)

enter image description here

最佳答案

这可能是由不同版本的 HTTP 客户端对类路径的依赖引起的。 ( Reference1Reference2 )确保类路径上只有一个版本。

关于java - 线程 "main"java.lang.NoSuchFieldError : INSTANCE in AWS SNS 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40104552/

相关文章:

android - 德尔福 FMX And​​roid 应用程序。如何打开短信窗口

azure - 使用 Azure AD B2C 的短信功能

java - 删除 AM/PM 标签 TimePickerDialog

java - Xerces - SchemaFactory 无法识别该功能,但 Validator 可以识别该功能

java - 如何从菜单栏打开框架

amazon-web-services - Amazon Web服务API是否支持条形码/UPC查询?

python - 更新 Python 以用于 AWS CLI

amazon-web-services - 如何在 Elastic Beanstalk Multicontainer docker 上使用 fluentd 日志驱动程序

java - JOOQ & 交易

android - 如何从非默认应用程序在 Android Kitkat 中发送短信而不写入短信提供商