十二月 18, 2023 11:48:14 下午 com.sun.xml.bind.v2.util.XmlFactory createTransformerFactory
严重: null
java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V
at com.sun.xml.bind.v2.util.XmlFactory.createTransformerFactory(XmlFactory.java:176)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.createTransformer(JAXBContextImpl.java:715)
at com.sun.xml.bind.v2.runtime.XMLSerializer.getIdentityTransformer(XMLSerializer.java:813)
at com.sun.xml.bind.v2.runtime.XMLSerializer.writeDom(XMLSerializer.java:805)
at com.sun.xml.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeBody(SingleReferenceNodeProperty.java:113)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:158)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:341)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
java - Invalid JAXP API when unmarshaling JAXB - Stack Overflow
java.lang.IllegalStateException: You are running with invalid JAXP api or implementation.
JAXP api/implementation of version 1.3.1 (included in JDK6) or higher is required. In case you are using ant,
make sure ant 1.7.0 or higher is used - older versions of ant contain JAXP api/impl version 1.2 (in xml-apis.jar).
If you want to keep using older ant versions, you have to configure it to use higher the JAXP api/impl versions.
It looks like the issue is due to an old version of Xalan.
It seems a minimum of version 2.7.0 is needed since JDK 5.
Another library was pulling in an older version so I excluded that from the Maven build and everything looks good now.
In my case it was caused by old version of xercesImpl. Dependency below fixed it
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
I solved this issue by using the following code. I am using JDK8 in my project
System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
In addition/support and to be more specific,
if you are running a maven or JPA project you should be able to right click on the dependency directory,
add dependency, and search for xalan. Add any versions 2.7.0 and up under the xalan:xalan list.
======解析=======
import javax.xml.transform.TransformerFactory;
他是在这个包里面的
https://mvnrepository.com/artifact/xml-apis/xml-apis
他有两个实现类,包名和类名一样,但是在不同的jar包里面的,所以识别不出来了
上面这个在JDK里面的rt.jar
下面的那个是在xml-apis.jar包里面
======解析完毕=======
//jdk8
System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");