我有一个基于 official guide 的简单 spring 项目消费网络服务。此示例似乎针对 JDK 8,但我想使用最新的 LTS,JDK 11。
我已经改编了 pom.xml
文件并添加了一些似乎已从 JDK 中删除的依赖项,即:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
但是,我似乎无法启动应用程序,总是收到此错误:
➜ spring-test git:(master) mvn spring-boot:run
[INFO] Scanning for projects...
...
org.springframework.ws.soap.client.SoapFaultClientException: Implementation of JAXB-API has not been found on module path or classpath.
at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault (SoapFaultMessageResolver.java:38)
at org.springframework.ws.client.core.WebServiceTemplate.handleFault (WebServiceTemplate.java:830)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive (WebServiceTemplate.java:624)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive (WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive (WebServiceTemplate.java:390)
at com.example.demo.CountryClient.getCountry (CountryClient.java:21)
at com.example.demo.DemoApplication.lambda$lookup$0 (DemoApplication.java:24)
at org.springframework.boot.SpringApplication.callRunner (SpringApplication.java:781)
at org.springframework.boot.SpringApplication.callRunners (SpringApplication.java:765)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:319)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:1215)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:1204)
at com.example.demo.DemoApplication.main (DemoApplication.java:13)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:543)
at java.lang.Thread.run (Thread.java:834)
尽管至少有两个问题( this 和 this )与此主题相关,但我已经尝试了在这些帖子中可以找到的所有版本组合,但仍然出现相同的错误。
我使用的特定 JDK+maven 版本是:
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T16:06:16+01:00)
Maven home: /usr/local/Cellar/maven/3.6.2/libexec
Java version: 11.0.4, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
我的测试代码是 here .
最佳答案
看看this answer并检查它是否可以帮助您。我们有几个项目使用 Java 11 和 Spring WS,一切正常。还要确保您的 pom.xml
目标是 Java 11:
<properties>
<java.version>11</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>
关于缺少的类,我们必须添加以下依赖项,仅此而已:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
关于spring-boot - JDK11 + Spring 启动 = JAXBException : Implementation of JAXB-API has not been found on module path or classpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58270761/