log4j 2.17.0 更新问题:ClassNotFoundException SetUtils
Issue with log4j 2.17.0 update: ClassNotFoundException SetUtils
版本升级到 log4j 2.17.0 后,在单元测试期间出现此异常:
java.lang.ClassNotFoundException: org.apache.logging.log4j.core.util.SetUtils
如何解决这个问题?
经过反复试验I found here that upgrading to log4j 2.17.0 implies a new dependency log4j-web
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.17.0</version>
</dependency>
我问过 Log4j 开发人员如何处理这个问题。
class 被视为内部,不得使用。
看看。 https://issues.apache.org/jira/browse/LOG4J2-3309
可能用于替换 class 的代码应该更像下面这样(使用:org.apache.commons.collections4
)
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.SetUtils;
// generic
Predicate<E> predicate = x -> (doSthWith(x));
final Set<E> resultSet = SetUtils.predicatedSet(setOfElements, predicate);
final String[] array = (String[]) resultSet.toArray();
// for example
Predicate<String> containsString = str -> (str.startsWith(stringToSearch));
final Set<String> resultSet = SetUtils.predicatedSet(setOfStrings, containsString);
final String[] arrayOfStrings= (String[]) resultSet.toArray();
版本升级到 log4j 2.17.0 后,在单元测试期间出现此异常:
java.lang.ClassNotFoundException: org.apache.logging.log4j.core.util.SetUtils
如何解决这个问题?
经过反复试验I found here that upgrading to log4j 2.17.0 implies a new dependency log4j-web
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.17.0</version>
</dependency>
我问过 Log4j 开发人员如何处理这个问题。 class 被视为内部,不得使用。
看看。 https://issues.apache.org/jira/browse/LOG4J2-3309
可能用于替换 class 的代码应该更像下面这样(使用:org.apache.commons.collections4
)
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.SetUtils;
// generic
Predicate<E> predicate = x -> (doSthWith(x));
final Set<E> resultSet = SetUtils.predicatedSet(setOfElements, predicate);
final String[] array = (String[]) resultSet.toArray();
// for example
Predicate<String> containsString = str -> (str.startsWith(stringToSearch));
final Set<String> resultSet = SetUtils.predicatedSet(setOfStrings, containsString);
final String[] arrayOfStrings= (String[]) resultSet.toArray();