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.*"})
相关推荐
长安不见几秒前
背景知识: 理解LimitLatch背后的AQS
java
小吕学编程3 分钟前
策略模式实战:Spring中动态选择商品处理策略的实现
java·开发语言·设计模式
weixin_438335409 分钟前
Spring Boot实现接口时间戳鉴权
java·spring boot·后端
q5673152324 分钟前
IBM官网新闻爬虫代码示例
开发语言·分布式·爬虫
DanCheng-studio25 分钟前
毕设 基于机器视觉的驾驶疲劳检测系统(源码+论文)
python·毕业设计·毕设
carpell27 分钟前
【语义分割专栏】3:Segnet实战篇(附上完整可运行的代码pytorch)
人工智能·python·深度学习·计算机视觉·语义分割
笨笨马甲30 分钟前
附加模块--Qt OpenGL模块功能及架构
开发语言·qt
pan_junbiao41 分钟前
Spring框架的设计模式
java·spring·设计模式
远方160942 分钟前
0x-2-Oracle Linux 9上安装JDK配置环境变量
java·linux·oracle
北执南念1 小时前
CompletableFuture+线程池使用案列
java