Веб-сервис JAX-WS с Spring Boot и JAX-WS RI - PullRequest
0 голосов
/ 08 мая 2020

Я пытаюсь создать веб-службу, используя Spring boot и JAX-WS RI . Следуя инструкциям в следующем руководстве https://herrho.com/2018/01/14/jax-ws-webservice-with-spring-boot-and-jax-ws-ri/

пом. xml

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- JAX-WS -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.2.10</version>
        </dependency>

        <!-- Spring JAX-WS Integration -->
        <dependency>
            <groupId>org.jvnet.jax-ws-commons.spring</groupId>
            <artifactId>jaxws-spring</artifactId>
            <version>1.9</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.java-websocket</groupId>
            <artifactId>Java-WebSocket</artifactId>
            <version>1.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

GreetingService.class

package com.example.WS;

import org.springframework.stereotype.Component;

import javax.jws.WebMethod;
import javax.jws.WebService;

@Component(value = "greetingService")
@WebService
public class GreetingService {

                @WebMethod
                public String greeting() {
                    return "Hello World!";
                }
}

BtsApplication.class

package com.example.WS;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

import com.sun.xml.ws.transport.http.servlet.WSSpringServlet;

@SpringBootApplication
@ImportResource(locations="jaxwsconfig.xml")
public class BtsApplication {

        public static void main(String[] args) throws Exception
        {
            SpringApplication.run (BtsApplication.class, args);
        }

        @Bean
        public ServletRegistrationBean<WSSpringServlet> servletRegistrationBean() 
        {
            return new ServletRegistrationBean<WSSpringServlet> (new WSSpringServlet(), "/hello");
        }
}

jaxwsconfig. xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:ws="http://jax-ws.dev.java.net/spring/core"
       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://jax-ws.dev.java.net/spring/core
        http://jax-ws.dev.java.net/spring/core.xsd
        http://jax-ws.dev.java.net/spring/servlet
        http://jax-ws.dev.java.net/spring/servlet.xsd"
>

    <wss:binding url="/hello">
        <wss:service>
            <ws:service bean="#greetingService"/>
        </wss:service>
    </wss:binding>

    <bean id="greetingServiceId" class="com.example.WS.GreetingService">
    </bean>


</beans>

In при запуске проекта у меня были следующие ошибки:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sun.xml.ws.transport.http.servlet.SpringBinding#0' defined in class path resource [jaxwsconfig.xml]: Cannot create inner bean '(inner bean)#2f74ea50' of type [org.jvnet.jax_ws_commons.spring.SpringService] while setting bean property 'service'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2f74ea50': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/RuntimeInlineAnnotationReader
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:389) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:134) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1444) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:882) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [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.connectedSensor.BTS.BtsApplication.main(BtsApplication.java:29) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_241]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_241]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_241]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2f74ea50': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/RuntimeInlineAnnotationReader
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:135) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:377) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 24 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/RuntimeInlineAnnotationReader
    at com.sun.xml.ws.model.WrapperBeanGenerator.<clinit>(WrapperBeanGenerator.java:77) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.model.RuntimeModeler.getRequestWrapperClass(RuntimeModeler.java:375) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:800) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:730) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:490) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:320) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:99) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:120) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:521) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:300) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:164) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:577) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:560) ~[jaxws-rt-2.2.10.jar:2.2.10]
    at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:368) ~[jaxws-spring-1.9.jar:na]
    at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:80) ~[jaxws-spring-1.9.jar:na]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_241]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_241]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_241]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_241]
    ... 44 common frames omitted

Это блокирует мой прогресс на несколько дней. Пожалуйста, мне нужна помощь. Спасибо.

...