列出带有Google Cloud Storage的存储桶会导致NoSuchMethodError,Java AppEngine [英] Listing buckets with Google Cloud Storage resulting in NoSuchMethodError, Java AppEngine
问题描述
试图只列出我的Google Cloud Storage项目中的存储桶,但不太明白为什么我不断出现以下错误:
Trying to just list the buckets in my Google Cloud Storage project but can't quite understand why i keep getting the following error:
java.lang.NoSuchMethodError:com.google.api.services.storage.model.Bucket.getIamConfiguration()Lcom/google/api/services/storage/model/Bucket $ IamConfiguration;
java.lang.NoSuchMethodError: com.google.api.services.storage.model.Bucket.getIamConfiguration()Lcom/google/api/services/storage/model/Bucket$IamConfiguration;
我正在使用以下servlet对其进行测试:
I'm testing it with the following servlet:
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
@WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
public Test() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
for (Bucket bucket : storage.list().iterateAll()) { //this line is giving the error
response.getWriter().write(bucket.getName());
}
}
}
在pom中,我有:
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.8</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.64.0</version>
</dependency>
此特定示例不需要以前的依赖关系,但是我需要在应用程序的另一部分使用它,我怀疑这可能是问题所在.任何想法可能出什么问题吗?
The former dependency isn't required for this specific example but i need it for another part of the application, I suspect this might be where the problem lies. Any ideas what could be going wrong?
推荐答案
发现了问题.我收到一个NoSuchMethodError,因为显然,即使将其指定为Maven依赖项,所需的库也未包含在项目中.开发服务器上的库和生产服务器上的库之间存在某种不匹配.
Found the problem. I was getting a NoSuchMethodError because apparently the library needed wasn't included in the project even though it was specified as a maven dependency. Some kind of mismatch between the libraries on the development server and the libraries on the production server.
Eclipse中的解决方案是删除所有相关的Google库,然后右键单击项目>构建路径>配置构建路径...>添加库...> Google Cloud Platform库>选择应用引擎API"和云存储".
The solution in Eclipse was to remove all the revelant Google libraries and add them again by right clicking on the project > Build Path > Configure Build Path... > Add Library... > Google Cloud Platform Libraries > Select "App Engine API" & "Cloud Storage".
这篇关于列出带有Google Cloud Storage的存储桶会导致NoSuchMethodError,Java AppEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!