当前位置: 首页 > 知识库问答 >
问题:

Spring-WS服务表示“没有用于forendpoint的适配器”,而据我所知,有

鄢飞鸾
2023-03-14

我试图编写一个相当简单的Spring-WS服务,它接受一个字符串并返回一个字符串,我已经定义了endpoint类,就我所知,一切看起来都很好。但是当我使用SOAP-UI访问服务时,会得到以下错误消息:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
                                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
                                    http://www.springframework.org/schema/web-services  
                                    http://www.springframework.org/schema/web-services/web-services-2.0.xsd  
                                     http://www.springframework.org/schema/context  
                                     http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="uk.co.company.product.identification" />
    <sws:annotation-driven />
    <!-- Our test service bean -->
    <bean id="IdentificationRequest"
        class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
        lazy-init="true">
        <property name="schemaCollection">
            <bean
                class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
                <property name="inline" value="true" />
                <property name="xsds">
                    <list>
                        <value>/schemas/identificationOperations.xsd</value>
                    </list>
                </property>
            </bean>
        </property>
        <property name="portTypeName" value="IdentificationService" />
        <property name="serviceName" value="IdentificationServices" />
        <property name="locationUri" value="/endpoints/" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.company.co.uk/product/identification/service"
    targetNamespace="http://www.company.co.uk/product/identification/service"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:element name="IdentificationRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="address" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="IdentificationResponse">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="identificationData" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>
package uk.co.company.product.identification.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class IdentificationServiceEndpoint {

    private static final String TARGET_NAMESPACE = "http://www.company.co.uk/product/identification/service";

    @Autowired
    private IdentificationService identificationService;

    @PayloadRoot(localPart="IdentificationRequest", namespace=TARGET_NAMESPACE)
    @ResponsePayload public  String getIdentificationData(@RequestPayload String address){
        return identificationService.getIdentificationData(address);
    }

    public void setIdentificationService(IdentificationService identificationService){
        this.identificationService = identificationService;
    }
}

生成的WSDL这是当我浏览到以下内容时生成的WSDL:

http://localhost:8080/IdentificationService/IdentificationRequest.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.company.co.uk/product/identification/service" xmlns:tns="http://www.company.co.uk/product/identification/service" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:sch="http://www.company.co.uk/product/identification/service" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xsd:schema targetNamespace="http://www.company.co.uk/product/identification/service" elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.co.uk/product/identification/service">
            <xsd:element name="IdentificationRequest">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="address" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>

            </xsd:element>

            <xsd:element name="IdentificationResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="identificationData" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="IdentificationRequest">
        <wsdl:part name="IdentificationRequest" element="tns:IdentificationRequest"> </wsdl:part>
    </wsdl:message>

    <wsdl:message name="IdentificationResponse">
        <wsdl:part name="IdentificationResponse" element="tns:IdentificationResponse"> </wsdl:part>
    </wsdl:message>

    <wsdl:portType name="IdentificationService">
        <wsdl:operation name="Identification">
            <wsdl:input name="IdentificationRequest" message="tns:IdentificationRequest"> </wsdl:input>
            <wsdl:output name="IdentificationResponse" message="tns:IdentificationResponse"> </wsdl:output>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="IdentificationServiceSoap11" type="tns:IdentificationService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="Identification">
            <soap:operation soapAction=""/>
            <wsdl:input name="IdentificationRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="IdentificationResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="IdentificationServices">
        <wsdl:port name="IdentificationServiceSoap11" binding="tns:IdentificationServiceSoap11">
            <soap:address location="http://localhost:8080/IdentificationService/endpoints/"/>
        </wsdl:port>

    </wsdl:service>
</wsdl:definitions>

SOAP消息:这些是我从SOAP-UI发送的SOAP消息和我所获得的信息。终点是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://www.company.co.uk/product/identification/service">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:IdentificationRequest>
         <address>test</address>
      </ser:IdentificationRequest>
   </soapenv:Body>
</soapenv:Envelope>

回应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">No adapter for endpoint [public java.lang.String uk.co.company.product.identification.service.IdentificationServiceEndpoint.getIdentificationData(java.lang.String)]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

为了完整起见,这里是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework.samples.service.service</groupId>
    <artifactId>IdentificationService</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>

        <!-- Generic properties -->
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Web -->
        <jsp.version>2.2</jsp.version>
        <jstl.version>1.2</jstl.version>
        <servlet.version>2.5</servlet.version>


        <!-- Spring -->
        <spring-framework.version>3.2.3.RELEASE</spring-framework.version>
        <spring.ws.version>2.0.0.RELEASE</spring.ws.version>

        <!-- Hibernate / JPA -->
        <hibernate.version>4.2.1.Final</hibernate.version>

        <!-- Logging -->
        <logback.version>1.0.13</logback.version>
        <slf4j.version>1.7.5</slf4j.version>

        <!-- Test -->
        <junit.version>4.11</junit.version>

        <!-- Context Path -->
        <context.path>IdentificationService</context.path>

    </properties>

    <dependencies>

        <!-- Spring MVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>
        <!-- Spring WS -->
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.xmlschema</groupId>
            <artifactId>xmlschema-core</artifactId>
            <version>2.0.1</version>
        </dependency>

        <!-- Apache Commons -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

        <!-- Other Web dependencies -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${servlet.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>${jsp.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Spring and Transactions -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>

        <!-- Logging with SLF4J & LogBack -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>



        <!-- Test Artifacts -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring-framework.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
            <plugins>
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                </executions>
                <configuration>
                    <clearOutputDir>false</clearOutputDir>
                    <outputDirectory>src/main/java</outputDirectory>
                    <schemaDirectory>src/main/webapp/schemas</schemaDirectory>  
                    <includeSchema>**/*.xsd</includeSchema>       
                    <enableIntrospection>false</enableIntrospection>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>${context.path}</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

共有1个答案

羊刚捷
2023-03-14

您的方法签名是关闭的,而不是字符串,它需要IdentificationRequestIdentificationResponse作为返回类型。

@PayloadRoot(localPart="IdentificationRequest", namespace=TARGET_NAMESPACE)
@ResponsePayload 
public IdentificationResponse getIdentificationData(@RequestPayload IdentificationRequest address){
    String identification = identificationService.getIdentificationData(address.getAddress());
    ObjectFactory factory = new ObjectFactory();
    IdentificationResponse response = factory.createIdentificationResponse();
    response.setIdentificationData(identification);
    return response;
}

您的方法应该类似于上面的内容。

 类似资料:
  • 我试图在spring-boot应用程序中使用apache-camel(2.15.2)来处理传入的web服务调用。 我在http://spring.io/guides/gs/production-web-service/下面创建了一个初始工作的Spring Boot项目(没有camel) 然后,我尝试将Camel:Spring Web服务组件集成为使用者,以便按照http://camel.apach

  • 我使用的是Spring 2.0.1。使用spring云总线发布并安装所有项目(2个服务和云配置服务器) 配置服务器还具有spring云配置监视器 我在我的Git reposroty中编辑文件(使用具有Spring Cloud Config本机配置文件的本地文件)。检测到更改,我在Cloud Config Server中看到以下行: 但是,其他服务都不会收到有关更新密钥的通知。 另一方面,如果我手动

  • 我尝试按照Spring入门指南“使用Spring MVC提供Web内容”,该指南除了使用Maven之外还使用了Spring Boot和Gradle。我为Eclipse安装了Gradle插件。 我希望使用Eclipse中的Tomcat服务器运行应用程序,因为我还遵循了“将Spring Boot JAR应用程序转换为WAR”指南,并更改了指南中提到的“build.gradle”文件。基本上,我添加了行

  • 我有一个简单的spring boot应用程序,它从JMS队列中获取消息,并将一些数据保存到日志文件中,但不需要web服务器。有没有办法在没有web服务器的情况下启动spring boot?

  • 问题内容: 嗨,我正在用React钩子编程一个页面,并且试图将从服务器获取的数据设置为状态。怎么它不起作用。我从服务器获取数据,但无法将其映射到状态。任何想法可能是什么问题? 来自服务器的数据 问题答案: 是async方法,因此您将无法在其下获取更新的数据。 否则您的代码是好的,如果您循环并显示它,它将反映在DOM中 运行下面的代码片段,并检查HTML和console两者,这将清除流程。

  • 我已经从spring的initialzr生成了一个Spring Boot配置服务器。 我已经用brew安装了rabbitmq。initialzr是使用启动版本2.1.1.RELEASE和云版本Greenwich.M3生成的。 简单的rest服务连接到rabbitmq队列。配置服务器连接到gitlab配置报告。 但是,当我提交并推送更改时,服务应用程序不会反映该更改。推送完成后,配置服务器将收到日志