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.*"})
相关推荐
java1234_小锋4 分钟前
[免费]基于Python的协同过滤电影推荐系统(Django+Vue+sqlite+爬虫)【论文+源码+SQL脚本】
python·django·电影推荐系统·协同过滤
奔跑吧邓邓子18 分钟前
【Java实战㉝】Spring Boot实战:从入门到自动配置的进阶之路
java·spring boot·实战·自动配置
ONLYOFFICE19 分钟前
【技术教程】如何将ONLYOFFICE文档集成到使用Spring Boot框架编写的Java Web应用程序中
java·spring boot·编辑器
叫我阿柒啊27 分钟前
Java全栈开发工程师的实战面试经历:从基础到微服务
java·微服务·typescript·vue·springboot·前端开发·后端开发
耶啵奶膘36 分钟前
uni-app头像叠加显示
开发语言·javascript·uni-app
看海天一色听风起雨落42 分钟前
Python学习之装饰器
开发语言·python·学习
cyforkk43 分钟前
Spring 异常处理器:从混乱到有序,优雅处理所有异常
java·后端·spring·mvc
Want5951 小时前
C/C++圣诞树①
c语言·开发语言·c++
生擒小朵拉1 小时前
STM32添加库函数
java·javascript·stm32
Z_z在努力1 小时前
【杂类】Spring 自动装配原理
java·spring·mybatis