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

回眸只為那壹抹淺笑 提交于 2019-12-01 00:19:12

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.

The following has worked for me

<dependency>
  <groupId>org.glassfish.jaxb</groupId>
  <artifactId>jaxb-runtime</artifactId>
  <version>2.3.0</version>
</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!