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

前端 未结 2 537
夕颜
夕颜 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:37

    The following has worked for me

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.0</version>
    </dependency>
    
    0 讨论(0)
  • 2021-01-06 19:42

    Try adding the following:

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.activation</groupId>
        <artifactId>javax.activation</artifactId>
        <version>1.2.0</version>
    </dependency>
    

    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.

    0 讨论(0)
提交回复
热议问题