TestNGException ClassCastException SAXParserFactoryImpl是Java自带的Xerces解析器——解决办法

java 复制代码
SLF4J: A number (1) of logging calls during the initialization phase have been intercepted and are
SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system.
SLF4J: See also http://www.slf4j.org/codes.html#replay
org.testng.TestNGException: 
An error occurred while instantiating class LogicTest: Provider com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl could not be instantiated: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:393)
	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:117)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183)
	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:128)
	at org.testng.TestRunner.initMethods(TestRunner.java:415)
	at org.testng.TestRunner.init(TestRunner.java:241)
	at org.testng.TestRunner.init(TestRunner.java:211)
	at org.testng.TestRunner.<init>(TestRunner.java:158)
	at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:545)
	at org.testng.SuiteRunner.init(SuiteRunner.java:159)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:114)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1260)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1247)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1101)
	at org.testng.TestNG.run(TestNG.java:1018)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Caused by: javax.xml.parsers.FactoryConfigurationError: Provider com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl could not be instantiated: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
	at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:204)
	at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:152)
	at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:277)
	at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
	at ch.qos.logback.core.joran.event.SaxEventRecorder.buildSaxParser(SaxEventRecorder.java:79)
	at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:57)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:151)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
	at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
	at LogicTest.<clinit>(CollectionUserStateLogicTest.java:29)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.powermock.modules.testng.internal.TestClassInstanceFactory.create(TestClassInstanceFactory.java:51)
	at org.powermock.modules.testng.internal.PowerMockClassloaderObjectFactory.newInstance(PowerMockClassloaderObjectFactory.java:46)
	at org.powermock.modules.testng.PowerMockObjectFactory.newInstance(PowerMockObjectFactory.java:43)
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382)
	... 17 more
Caused by: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
	at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:190)
	... 43 more
Disconnected from the target VM, address: '127.0.0.1:50195', transport: 'socket'

加入注解:

java 复制代码
@PowerMockIgnore({"javax.management.*", "javax.xml.*", "javax.net.ssl.*", "org.xml.sax.*", "org.w3c.dom.*", "org.springframework.*", "org.apache.log4j.*", "com.ctrip.framework.*"})
相关推荐
蚰蜒螟3 分钟前
深入解析JVM字节码解释器执行流程(OpenJDK 17源码实现)
开发语言·jvm·python
keke109 分钟前
Java【14_2】接口(Comparable和Comparator)、内部类
java·开发语言
思茂信息13 分钟前
CST软件对OPERA&CST软件联合仿真汽车无线充电站对人体的影响
c语言·开发语言·人工智能·matlab·汽车·软件构建
墨绿色的摆渡人17 分钟前
pytorch小记(二十):深入解析 PyTorch 的 `torch.randn_like`:原理、参数与实战示例
人工智能·pytorch·python
CN.LG20 分钟前
Java 乘号来重复字符串的功能
java·开发语言
川川菜鸟24 分钟前
2025长三角数学建模C题完整思路
c语言·开发语言·数学建模
萌新下岸多多关照25 分钟前
Java中synchronized 关键字
java·开发语言
中国lanwp26 分钟前
使用Maven部署WebLogic应用
java·maven
醍醐三叶28 分钟前
C++文件操作--2 二进制文件操作
开发语言·c++
剽悍一小兔32 分钟前
linux,我启动一个springboot项目, 用java -jar xxx.jar & ,但是没多久这个java进程就会自动关掉
开发语言