java.lang.ClassCastException:org.apache.logging.slf4j.SLF4JLoggerContext 无法转换为 org.apache.logging.log4j.core.LoggerContext

问题描述 投票:0回答:1

我正在尝试通过 API 创建 SpellChecker 程序。这是我的代码:

拼写检查.java

package com.spell;

import org.xeustechnologies.googleapi.spelling.SpellChecker;
import org.xeustechnologies.googleapi.spelling.SpellCorrection;
import org.xeustechnologies.googleapi.spelling.SpellResponse;

public class SpellCheck {

    public static void main(String[] args)
    {

        SpellChecker checker = new SpellChecker();

        SpellResponse spellResponse = checker.check( "helloo worlrd" );

        for( SpellCorrection sc : spellResponse.getCorrections() ) 
            System.out.println( sc.getValue() );

    }
}

依赖关系

运行后出现错误:

线程“main”中的异常 java.lang.ExceptionInInitializerError 在 com.spell.SpellCheck.main(SpellCheck.java:12) 引起原因:java.lang.ClassCastException:org.apache.logging.slf4j.SLF4JLoggerContext无法转换为org.apache.logging.log4j.core.LoggerContext 在 org.apache.log4j.Logger$PrivateManager.getContext(Logger.java:59) 在 org.apache.log4j.Logger.getLogger(Logger.java:41) 在 org.xeustechnologies.googleapi.spelling.SpellChecker.(SpellChecker.java:50) ... 1 更多

java jakarta-ee dependency-injection log4j
1个回答
0
投票

看起来

org.xeustechnologies.google.api.spelling.SpellChecker
使用log4j,而您正在使用slf4j。尝试将 log4j-over-slf4j 添加到类路径中以桥接 log4 以使用 slf4j。

© www.soinside.com 2019 - 2024. All rights reserved.