. lang。NoSuchMethodError:com.google.common.collect.FluentIterable.toList()Lcom /谷歌/共同/收集/ ImmutableList;

时间:2021-11-20 20:49:26

I'm using the Google Guava library for tasks like sorting and filtering of a java.util.List<T> in a Java EE 7 application.

我正在使用谷歌番石榴库进行排序和筛选java.util等任务。在Java EE 7应用程序中列出

Given below an example of filtering a java.util.List<T> based on a list of filters in a CDI bean.

下面给出一个过滤java.util的示例。列表 基于CDI bean中的过滤器列表。

@Named
@ViewScoped
public class Bean extends LazyDataModel<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private final class Filtering implements Predicate<T> {

        private final Map<String, Object> filters;

        public Filtering(Map<String, Object> filters) {
            this.filters = filters;
        }

        @Override
        public boolean apply(T p) {
            if (p == null) {
                return false;
            }

            Integer id = (Integer) filters.get("id");

            if (id != null && !p.getId().equals(id)) {
                return false;
            }

            BigDecimal size = (BigDecimal) filters.get("size");

            if (size != null && ((p.getSize().compareTo(size) < 0))) {
                return false;
            }
            return true;
        }
    }
}

The nested class can be used to filter a java.util.List<T> from within the CDI bean as follows.

嵌套类可用于筛选java.util。从CDI bean中列出 ,如下所示。

List<T> list = //Initialize the list here to be filtered.

//...

list = FluentIterable.from(list).filter((new Filtering(filters))).toList();

Where filters is a java.util.Map<String, Object> holding a list of filters.

过滤器是java.util。映射 ,包含一个过滤器列表。 ,对象>


This was working fine previously in a Java EE application with JSF Managed Beans (on GlassFish 4.0).

这在以前的Java EE应用程序中使用JSF托管bean(在GlassFish 4.0中)运行良好。

I migrated this application to GlassFish 4.1 with CDI Managed Beans and the following exception occurred.

我使用CDI托管bean将此应用程序迁移到GlassFish 4.1,并发生了以下异常。

SEVERE:   java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.toList()Lcom/google/common/collect/ImmutableList;
    at util.mesurements.custom.beans.BackNeckDepthManagedBean.load(BackNeckDepthManagedBean.java:184)
    at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:838)
    at org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:102)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:78)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:692)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219)
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:430)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at filter.NoCacheFilter.doFilter(NoCacheFilter.java:28)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:722)

I'm using Guava 17.0 on both the applications (double checked it).

我在两个应用程序上都使用了Guava 17.0(重复检查)。

Why does Guava dislike CDI beans. What might be the solution/workaround?

为什么番石榴不喜欢CDI咖啡豆?解决方案/解决方案是什么?


UPDATE :

更新:

I tried changing the version to 18.0 but nothing new happened.

我试着把版本改成18。0,但是什么都没发生。

2 个解决方案

#1


9  

You have multiple versions of Guava on your classpath. NoSuchMethodError in a Guava class comes here on SO maybe once per week. Switching to a newer version won't help as long you don't get rid of the old one. Print out the location of FluentIterable.class and get rid of that JAR.

您的类路径中有多个版本的番石榴。番石榴课上的nosuchmethderror会每周来一次。只要你不摆脱旧版本,切换到更新的版本就不会有任何帮助。打印出FluentIterable的位置。把罐子拿出来。

As Frank Pavageau commented, this location can be obtained as

正如Frank Pavageau所说,这个位置可以被获得为

FluentIterable.class.getProtectionDomain().getCodeSource().getLocation().toExte‌​rnalForm()

#2


5  

This is a known GlassFish issue. With GlassFish 4.1 and no other modifications, Guava 13.0.1 is used so when you use features not present in that version, you will get errors like the one you stated. In my case, it was java.lang.IncompatibleClassChangeError: Implementing class.

这是一个已知的玻璃鱼问题。对于GlassFish 4.1,没有其他修改,使用的是Guava 13.0.1,因此当您使用版本中没有的特性时,您将会得到与您所声明的一样的错误。在我的例子中,是java.lang。IncompatibleClassChangeError:实现类。

In the comments of the bug report it is suggested to replace glassfish/modules/guava.jar. This seems to be the easiest solution. Another approach is to use a custom class loader.

在bug报告的评论中,建议替换glassfish/modules/guav .jar。这似乎是最简单的解决方案。另一种方法是使用自定义类装入器。

Edit: If you add <class-loader delegate="false"/> to your glassfish-web.xml, then Guava is loaded from the WAR.

编辑:如果将 添加到glassfish-web中。然后番石榴从战争中被装载。

#1


9  

You have multiple versions of Guava on your classpath. NoSuchMethodError in a Guava class comes here on SO maybe once per week. Switching to a newer version won't help as long you don't get rid of the old one. Print out the location of FluentIterable.class and get rid of that JAR.

您的类路径中有多个版本的番石榴。番石榴课上的nosuchmethderror会每周来一次。只要你不摆脱旧版本,切换到更新的版本就不会有任何帮助。打印出FluentIterable的位置。把罐子拿出来。

As Frank Pavageau commented, this location can be obtained as

正如Frank Pavageau所说,这个位置可以被获得为

FluentIterable.class.getProtectionDomain().getCodeSource().getLocation().toExte‌​rnalForm()

#2


5  

This is a known GlassFish issue. With GlassFish 4.1 and no other modifications, Guava 13.0.1 is used so when you use features not present in that version, you will get errors like the one you stated. In my case, it was java.lang.IncompatibleClassChangeError: Implementing class.

这是一个已知的玻璃鱼问题。对于GlassFish 4.1,没有其他修改,使用的是Guava 13.0.1,因此当您使用版本中没有的特性时,您将会得到与您所声明的一样的错误。在我的例子中,是java.lang。IncompatibleClassChangeError:实现类。

In the comments of the bug report it is suggested to replace glassfish/modules/guava.jar. This seems to be the easiest solution. Another approach is to use a custom class loader.

在bug报告的评论中,建议替换glassfish/modules/guav .jar。这似乎是最简单的解决方案。另一种方法是使用自定义类装入器。

Edit: If you add <class-loader delegate="false"/> to your glassfish-web.xml, then Guava is loaded from the WAR.

编辑:如果将 添加到glassfish-web中。然后番石榴从战争中被装载。