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.*"})
相关推荐
拼搏@36 分钟前
第十六天,7月10日,八股
java·mybatis
Sylvia-girl4 小时前
Java——抽象类
java·开发语言
Yana.nice6 小时前
Bash函数详解
开发语言·chrome·bash
江沉晚呤时7 小时前
在 C# 中调用 Python 脚本:实现跨语言功能集成
python·microsoft·c#·.net·.netcore·.net core
Touper.7 小时前
Redis 基础详细介绍(Redis简单介绍,命令行客户端,Redis 命令,Java客户端)
java·数据库·redis
m0_535064607 小时前
C++模版编程:类模版与继承
java·jvm·c++
电脑能手8 小时前
如何远程访问在WSL运行的Jupyter Notebook
ide·python·jupyter
虾条_花吹雪8 小时前
Using Spring for Apache Pulsar:Message Production
java·ai·中间件
tomorrow.hello8 小时前
Java并发测试工具
java·开发语言·测试工具
Edward-tan8 小时前
CCPD 车牌数据集提取标注,并转为标准 YOLO 格式
python