当我们使用最新的commons-collections4-4.0jar时,我们会收到一条错误消息,如下所示,关于使用ComparatorChain和BeanComparator进行排序选项。你知道这有什么问题吗?我们使用commons-bean utile-1.9.2.jar for beanutils。
@SuppressWarnings("unchecked")
private void testCommonsChain() {
ComparatorChain comparator = new ComparatorChain();
List<TestDataBean> testDataBeanList = this.createTestDataBeanList();
comparator.addComparator(new BeanComparator<TestDataBean>("name"), true);
comparator.addComparator(new BeanComparator<TestDataBean>("kngk"));
Collections.sort(testDataBeanList, comparator);
this.printData(testDataBeanList);
}
private void testCommonsChain() {
ComparatorChain<TestDataBean> comparator = new ComparatorChain<TestDataBean>();
List<TestDataBean> testDataBeanList = this.createTestDataBeanList();
comparator.addComparator(new BeanComparator<TestDataBean>("name"), true);
comparator.addComparator(new BeanComparator<TestDataBean>("kngk"));
Collections.sort(testDataBeanList, comparator);
this.printData(testDataBeanList);
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/comparators/ComparableComparator
at org.apache.commons.beanutils.BeanComparator.<init>(BeanComparator.java:87)
at logic.TestComparator.testCommonsChain(TestComparator.java:36)
at logic.TestComparator.executeComparator(TestComparator.java:19)
at myTestOrange.TestMain.main(TestMain.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.comparators.ComparableComparator
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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
答案 0 :(得分:1)
至于它有什么问题:查看POM文件,commons-beanutils-1.9.2取决于commons-collections-3.2.1。问题是common-beanutils引用了commons-collections-4.4.0中不再可用的类。