JAXB / Java 11 / Tomcat - DataHandler No default constructor

百般思念 提交于 2021-02-11 14:23:14

问题


I have some trouble with JAXB, i found out that it exists many implementations of it, i used JBoss and the code worked well (Metro JAXB), now with tomcat and com.sun.xml.bind.. it doesn't, it cannot convert the Base64 encoded String into a DataHandler. Now i recompiled it again and i'm trying if the @XMLAttachmentRef would solve my trouble.

[com.sun.xml.bind.v2.ClassFactory]  No default constructor found on class javax.activation.DataHandler
java.lang.NoSuchMethodException: javax.activation.DataHandler.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3349)
    at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
    at com.sun.xml.bind.v2.ClassFactory.tryGetDeclaredConstructor(ClassFactory.java:107)

What i understood is that it fails because the DataHandler does not have a null args constructor.

I'm using OSGI i asked to my self if i could change the JAXB by removing com.sun.xml.bind and add some other jars to get it injected?


回答1:


So after > 10h of debugging i have found the cause:

Class TypeInfoSetImpl Method getTypeInfo Here makes JAXB a lookup into the built in types in a hashmap, it compares the class types with hashcode(), but my two javax.activation.DataHandler had two different classloaders, that causes that they are different, so it returned null and the class javax.activation.DataHandler was reconized as pojo custom class that can instantiated with null args constructor.

Deleting the secound jar resolved my problem.



来源:https://stackoverflow.com/questions/61612982/jaxb-java-11-tomcat-datahandler-no-default-constructor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!