spring-guides / gs-consuming-web-service

Consuming a SOAP web service :: Learn how to create a client that consumes a WSDL-based service
http://spring.io/guides/gs/consuming-web-service
Apache License 2.0
135 stars 166 forks source link

JAXB-API cannot be found even if I added the dependency in pom.xml #48

Closed litengyao closed 4 years ago

litengyao commented 4 years ago

I use JDK 1.8 to test the example codes with IDEA 2020, but JAXB-API cannot be found even if I added the dependecies in pom.xml. The detailed error information is as following:

2020-05-03 12:23:36.951 ERROR 11992 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at com.example.demo2.Demo2Application.main(Demo2Application.java:14) [classes/:na]
**Caused by: 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) ~[spring-ws-core-3.0.8.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:830) ~[spring-ws-core-3.0.8.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:624) ~[spring-ws-core-3.0.8.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) ~[spring-ws-core-3.0.8.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) ~[spring-ws-core-3.0.8.RELEASE.jar:na]
    at com.example.demo2.CountryClient.getCountry(CountryClient.java:24) ~[classes/:na]
    at com.example.demo2.Demo2Application.lambda$lookup$0(Demo2Application.java:25) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    ... 5 common frames omitted

Could you please help me, thank you!

dsyer commented 4 years ago

I don’t think that error is from JDK8 (see reference to “module path”). It should work with JDK11 (or higher) out of the box if you use the code from the “complete” sample. Check your JDK version?

litengyao commented 4 years ago

Thank you. But actually, I use JDK 8 indeed. All codes and implementations are the same with the guide from spring.io. The module and lib configuration in IDEA 2020 is as illustrated in the following figures:

image

image

image

For the problem, I cannot find proper solutions. Could you please give me some help again? Thank you:)

dsyer commented 4 years ago

It works for me. Maybe you have a bad jar file? JAXB is included in JDK8, so if you are really using that you wouldn’t see this error. Also, even for JDK11 there’s only one jar you need to add (it’s there in the sample).

litengyao commented 4 years ago

Thank you, I'll check my configurations about JDK once again.

litengyao commented 4 years ago

Unfortunately, I cannot accomplish the guide with the error for a long time:

Exception in thread "main" org.springframework.ws.soap.client.SoapFaultClientException: Implementation of JAXB-API has not been found on module path or classpath.

Considering the long time on the problem, I decided to find another solution to replace spring web service. It's a pity. In the future, I will make another try.

Thank you very much:)

bmccann36 commented 4 years ago

@litengyao I was getting the exact same error as you and was able to fix it. Our root issue may be the same. See this previously closed issue https://github.com/spring-guides/gs-consuming-web-service/issues/40#issuecomment-540584682

In my case it was because server was Java 11 and client was Java 8. The thing that makes this error confusing to debug is that it is not actually with the client code. I would assume that if you tried temporarily commenting out the "lookup" method of type CommandLine runner the app would start up fine and you would get no Error. The error happens when you try to call the server. I think you can still use Java 11 on the server you just have to add the jaxb dependency. See the linked comment for details

litengyao commented 4 years ago

Thank you for your comments. When I met with the problem 6 days ago, I tried to add any necessary dependency to support the code running, but it did not work. The jaxb dependencies that I added in pom.xml were:

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</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>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
        </dependency>

Finally, instead, I use apache CXF to implment Web Service developments, which also spports Spring Boot with Java 14. When developing, CXF is easy to integrate with Spring boot and convenient to facilitate developing applications with jax-ws. Thus, it is an alternative solution. Related guide doc can be found at Apache CXF --SpringBoot.