如何替换--add-modules java.xml.ws [英] How to replace --add-modules java.xml.ws

查看:114
本文介绍了如何替换--add-modules java.xml.ws的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实将基于Maven的项目迁移到SpringBoot 2.0和Java 9.在这个过程中,我不得不添加一些依赖项来摆脱有关模块的Java 9警告(仍然可以使用--add-modules添加)。

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).

但是我无法摆脱 - add-modules java.xml.ws 。正如 JEP 320 中所述,添加依赖项:

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>

这些依赖项允许运行 mvn test 到跑过,匆匆处理。 IntelliJ IDE的构建也可以。

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

然而,当启动Spring Boot应用程序时,我得到以下运行时异常:

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

我错过了哪些Maven依赖项? JarFinder 告诉我实施类是jaxb-impl的一部分,但仅限于版本2.2.12。那么这个实现在哪里消失了?

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?

推荐答案

你还需要jaxb-runtime:

You need also jaxb-runtime:

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

我觉得你不需要任何 com.sun 依赖项,使用glassfish实现:

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>

作为旁注,我认为至少进行一次集成测试是好的(maven故障保险一个)开始春天的背景。如果你有一个确保你至少使用surefire和failsafe 2.21.0(以前的版本有 - add-modules 的错误)。

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).

这篇关于如何替换--add-modules java.xml.ws的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆