使用Guava时端点API生成错误

时间:2013-02-22 10:25:45

标签: guava google-cloud-endpoints

我们正在使用带有Guava的Appengine Endpoints Java,当在端点方法中使用Function时,API生成器会返回异常。

函数不是方法签名的一部分。它只是在方法内部用来转换列表。注释掉这个身体部位并生成OK。

Guava肯定在类路径中,应用程序的其他部分通常使用它。

我不确定它与Guava或任何外部API有关会产生同样的错误。

方法:

@ApiMethod(
    httpMethod = "GET",
    name = "ledgers.accountgroups.get",
    path="ledgers/{ledgerId}/accountgroups")
public Collection<IAccountGroup> listAccountGroups(@Named("ledgerId") String ledgerId, User user) throws Exception {
collaboratorDAO.assertCollaboratorOn(ledgerId, user);
List<Group> groups = accountGroupsDAO.getAccountGroups(ledgerId);
List<IAccountGroup> transformedGroups = Lists.transform(groups, new Function<Group, IAccountGroup>() {
    @Override
    public IAccountGroup apply(Group group) {
        return group.createClient();
    }
});
return transformedGroups;

}

例外:

INFO: Successfully processed ./war/WEB-INF/appengine-web.xml
interface com.google.api.server.spi.config.Api
interface com.google.api.server.spi.config.Api
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
    at java.lang.Class.getDeclaredMethods(Class.java:1793)
    at com.google.api.server.spi.MethodHierarchyReader.addServiceMethods(MethodHierarchyReader.java:174)
    at com.google.api.server.spi.MethodHierarchyReader.readMethodHierarchyIfNecessary(MethodHierarchyReader.java:44)
    at com.google.api.server.spi.MethodHierarchyReader.getEndpointOverrides(MethodHierarchyReader.java:99)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.readEndpointMethods(ApiConfigAnnotationReader.java:215)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.loadEndpointMethods(ApiConfigAnnotationReader.java:92)
    at com.google.api.server.spi.config.ApiConfigLoader.loadConfiguration(ApiConfigLoader.java:55)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfigObjects(AnnotationApiConfigGenerator.java:237)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfig(AnnotationApiConfigGenerator.java:185)
    at com.google.api.server.spi.tools.GenApiConfigAction.genApiConfig(GenApiConfigAction.java:78)
    at com.google.api.server.spi.tools.GetClientLibAction.getClientLib(GetClientLibAction.java:66)
    at com.google.api.server.spi.tools.GetClientLibAction.execute(GetClientLibAction.java:49)
    at com.google.api.server.spi.tools.EndpointsTool.execute(EndpointsTool.java:66)
    at com.google.api.server.spi.tools.EndpointsTool.main(EndpointsTool.java:92)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 16 more

此时不使用番石榴非常简单,而且有效。我只想知道为什么会发生这种情况,因为我需要在其他部分使用番石榴。

更新

我认为它与以下问题相同:

Google Cloud Endpoints doesn't know about the Work class from Objectify 4 Transaction, causing ClassNotFoundException

任何提示?

谢谢!

0 个答案:

没有答案