spring jakpage.xml.bind.PropertyException:name:com.sun.xml.bind.namespacePrefixMapper value -com.abc $jakpacePrefixMapperImpl@65c3d713

gcuhipw9  于 11个月前  发布在  Spring
关注(0)|答案(2)|浏览(81)

迁移到java17.So将包迁移到Jakarta.*。
版本:jakbet.xml.bind-api = 4.0.0,com.sun.xml.bind/jaxb-impl = 2.0.1
现在面临的问题是:
jakmart.xml.bind.PropertyException:name:com.sun.xml.bind.namespacePrefixMapper value:com.abc $jakmart.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:355)at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:492)
如果我将- com.sun.xml.bind/jaxb-impl移动到4.0.2,我不会看到-pacepresefixMapper。
在更改为org.glassfish.jaxb:jaxb-runtime之后,我看到如下错误:“jakslip.xml.bind.PropertyException:name:org.glassfish.jaxb.runtime.marshaller. pacePrefixMapper value:com.fusionone.wsg.provision.resource.BaseMarshaller$pacePrefixMapperImpl@4cd619db at jakslip.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl. java:355)at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:492)
更多代码:

public static String      NAMESPACE_PROPERTY         = 
     "org.glassfish.jaxb.runtime.marshaller.
     NamespacePrefixMapper";
     public static String A1NAMESPACE  = "a1";
     public static String NO_NAMESPACE = "";
     public static String NAMESPACEURI                     ="http://www.example.com/xmlns/a1";

    public BaseMarshaller(JAXBContext jaxContext) throws         JAXBException {
        this(jaxContext, Constants.SCHEMA_LOCATION);
    }
    
    public BaseMarshaller(JAXBContext jaxContext, String             schemaLocation) throws JAXBException {
        m = jaxContext.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,            Boolean.TRUE);
        m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,            schemaLocation);
        m.setProperty(Constants.NAMESPACE_PROPERTY, new           NamespacePrefixMapperImpl());-> **this is giving exception**
    }

    new NamespacePrefixMapperImpl() calls , below :
        public static class NamespacePrefixMapperImpl  extends          NamespacePrefixMapper {
    
        @Override
        public String getPreferredPrefix(String namespaceUri,             String suggestion, boolean arg2) {
            if (Constants.NAMESPACEURI.equals(namespaceUri)) {
                return Constants.A1NAMESPACE;
            }      
                        return Constants.NO_NAMESPACE;
        }
    }

字符串

vngu2lb8

vngu2lb81#

当迁移到JAXB 4时,您应该使用以下代码而不是com.sun.xml.bind:jaxb-impl

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>4.0.4</version> <!-- latest version at the moment -->
</dependency>

字符串
您还应该在API和impl之间对齐主版本号。
命名空间前缀Map器已从com.sun.xml.bind.marshaller.NamespacePrefixMapper移动到org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper

umuewwlo

umuewwlo2#

更新属性与关键'org.glassfish.jaxb.namespacePrefixMapper' .问题得到解决!
m.setProperty(“org.glassfish.jaxb.namespacePrefixMapper”,new namespacePrefixMapperImpl());

相关问题