junit java.lang.ClassCastException:无法将DocumentBuilderFactoryImpl强制转换为DocumentBuilderFactory

rfbsl7qr  于 2023-03-30  发布在  Java
关注(0)|答案(6)|浏览(167)

我正在使用powermockpowermock-easymock-1.5-full.jar。出现以下异常。
这些是我的类路径中的所有jar文件,并作为powermock包从http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-testng-1.5.zip&can=2&q=下载

  1. easymock-3.1.jar
  2. javassist-3.17.1-GA.jar
  3. jcommander-1.27.jar
  4. objenesis-1.2.jar
  5. snakeyaml-1.6.jar
  6. testng-6.8.jar
  7. bsh-2.0b4.jar
  8. cglib-nodep-2.2.2.jar
  9. powermock-easymock-1.5-full.jar
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at com.eibus.localization.message.MessageSet._tryGetMessageText(MessageSet.java:268)
    at com.eibus.localization.message.Message._tryGetMessage(Message.java:135)
    at com.eibus.localization.message.Message.getMessage(Message.java:110)
    at com.eibus.localization.message.Message.getMessageWithLocaleFallBack(Message.java:155)
    at com.eibus.localization.StringFormatter.getMessageWithFallBack(StringFormatter.java:141)
    at com.eibus.localization.StringFormatter.format(StringFormatter.java:43)
    at com.eibus.localization.LocalizableComposite.getMessage(LocalizableComposite.java:42)
    at com.eibus.localization.exception.LocalizableException.getMessage(LocalizableException.java:168)
    at com.eibus.localization.exception.LocalizableException.getLocalizedMessage(LocalizableException.java:130)
    at java.lang.Throwable.toString(Throwable.java:479)
    at java.lang.String.valueOf(Unknown Source)
    at java.io.PrintWriter.println(Unknown Source)
    at java.lang.Throwable$WrappedPrintWriter.println(Unknown Source)
    at java.lang.Throwable.printStackTrace(Throwable.java:654)
    at java.lang.Throwable.printStackTrace(Throwable.java:720)
    at org.junit.runner.notification.Failure.getTrace(Failure.java:67)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:68)
    at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:100)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:41)
    at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:97)
    at org.junit.internal.runners.MethodRoadie.addFailure(MethodRoadie.java:154)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.handleException(PowerMockJUnit44RunnerDelegateImpl.java:359)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl$PowerMockJUnit49MethodRunner.executeTest(PowerMockJUnit49RunnerDelegateImpl.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

请帮帮我

cxfofazt

cxfofazt1#

以下是对我有效的方法:

@PowerMockIgnore({"javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*",  "org.springframework.context.*", "org.apache.log4j.*"})
ibps3vxo

ibps3vxo2#

如果这是一个与PowerMock相关的问题,那么你可以尝试用以下内容注解你的测试类:

@PowerMockIgnore({"javax.xml.parsers.*", "com.sun.org.apache.xerces.internal.jaxp.*"})
n3ipq98p

n3ipq98p3#

你可以忽略log4j.。我有同样的问题与jptool日志。我已经解决了忽略它这里是我的代码@PowerMockIgnore({“jptools."})

p1iqtdky

p1iqtdky4#

这是一个PowerMock问题,我遇到了这个错误:

java.lang.ClassCastException: class sun.security.provider.ConfigFile

你可以用这个注解来解决这个问题,试着用以下内容来注解你的测试类:

@PowerMockIgnore({"javax.management.*", "java.lang.*", "javax.security.*" })
4xy9mtcn

4xy9mtcn5#

您可以在test/resources/org/powermock/extensions/中创建一个configuration.properties文件,其内容为:

powermock.global-ignore=org.apache.xerces.*,javax.xml.parsers.*,org.xml.sax.*

注意:属性值中必须使用逗号分隔,并且不能有空格,否则将无法工作!软件包列表取决于您的项目的依赖项。
PowerMock配置here

jecbmhm3

jecbmhm36#

我在PowerMock v1.5.1和Log4j 2.19.0中遇到了类似的问题
为了解决这个问题,我将org.apache.logging.logj4.*添加到现有的@PowerMockIgnore注解中,如下所示:

@PowerMockIgnore({"javax.management.*", "org.apache.logging.log4j.*"})
-- Irrelevant annotations removed for brevity --
public class DeclarationRulesDelegateTest extends RulesTest {

相关问题