How to replace --add-modules java.xml.ws

风流意气都作罢 提交于 2019-12-08 08:05:51

问题


I did migrate my Maven based project to SpringBoot 2.0 and Java 9. In the process, I had to add some dependencies to get rid of Java 9 warnings regarding modules (that still can be added with --add-modules).

However I am unable to get rid off --add-modules java.xml.ws. As suggested in JEP 320, adding dependencies:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>

These dependencies allow to run mvn test to run through. The build from IntelliJ IDE also works.

However when starting the Spring Boot application, I get the following runtime exception:

...
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
    at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
    ... 64 more

What Maven dependencies am I missing? JarFinder tells me that the implementation class is part of jaxb-impl, but only up to version 2.2.12. So where did this implementation disappear to?


回答1:


You need also jaxb-runtime:

    <dependency>                                                            
        <groupId>org.glassfish.jaxb</groupId>                               
        <artifactId>jaxb-runtime</artifactId>                               
        <version>2.3.0</version>                                            
    </dependency> 

And I don't think you need any of the com.sun dependencies, use glassfish ones for the implementation:

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

As a side note, I think it is good to have at least one integration test (maven failsafe one) that starts the spring context. If you will have one make sure you use at least surefire and failsafe 2.21.0 (previous version had a bug with --add-modules).



来源:https://stackoverflow.com/questions/49480092/how-to-replace-add-modules-java-xml-ws

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