[英]The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved
[英]Maven project "AmazonS3ClientBuilder() has private access in com.amazonaws.services.s3.AmazonS3ClientBuilder"
我有一個文件,很早就收到了標題中提到的錯誤:
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.PutObjectResult;
import java.io.File;
public static void main(String[] args) throws Exception {
createAndPopulateSimpleBucket();
}
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = new AmazonS3ClientBuilder().standard().build();
}
當我調用 new AmazonS3ClientBuilder() 時,標題中出現錯誤。
我是 Maven 的新手,我想我的 pom 設置正確。 這里是:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>AWSJavaHelloWorld</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.715</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>
</project>
我猜我的 pom 有問題,但我不知道是什么。 當我包含來自 AWS 開發工具包的所有內容(而不是僅真正包含 S3 依賴項)時,我也會遇到相同的錯誤。
那么,任何人都可以發現有什么問題嗎?
AmazonS3ClientBuilder
的文檔指出此類不公開public
無參數構造函數。 這意味着您不能從您的類中調用new AmazonS3ClientBuilder()
。
幸運的是,這個類提供了兩個static
工廠方法; 其中一種方法AmazonS3ClientBuilder#defaultClient
創建AmazonS3
實例(客戶端),另一種方法AmazonS3ClientBuilder#standard
創建構建器的實例。
知道了這一點,您可以使用以下代碼段之一替換您的代碼:
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
}
或者:
public static void createAndPopulateSimpleBucket() throws Exception {
AmazonS3 s3client = AmazonS3ClientBuilder.standard().build();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.