Proper way to use Spring JAXB Marshaller with Java 9 without defining additional modules

前端 未结 2 538
夕颜
夕颜 2021-01-06 18:56

To illustrate my issue, I created a small spring boot sample application. The purpose of the application is to create a Jaxb2Marshaller bean.

@S         


        
2条回答
  •  迷失自我
    2021-01-06 19:42

    Try adding the following:

    
        org.glassfish.jaxb
        jaxb-core
        2.3.0
    
    
        com.sun.activation
        javax.activation
        1.2.0
    
    

    jaxb-core contains com.sun.xml.bind.v2.model.annotation.AnnotationReader (and seems to be a required dependency of jaxb-runtime, at least in your case), while javax.activation is needed by jaxb-api due to the usage of DataHandler by the latter.

    Also, there is no a single bean class, so the marshaller will fail initialization. I've added the following

    @XmlRootElement
    public class MyBean {
    }
    

    and replaced

    bean.setContextPath("ch.sahits.game.helloworld");
    

    with

    bean.setClassesToBeBound(MyBean.class);
    

    after which the application has started.

提交回复
热议问题