Web services 使用ApacheCXF创建基于SOAP的web服务?
我知道如何使用CXF创建基于REST的web服务,并自动将数据反序列化为对象。但是如何使用CXF创建基于SOAP的web服务呢?我需要将SOAP调用数据反序列化到java对象Web services 使用ApacheCXF创建基于SOAP的web服务?,web-services,soap,cxf,Web Services,Soap,Cxf,我知道如何使用CXF创建基于REST的web服务,并自动将数据反序列化为对象。但是如何使用CXF创建基于SOAP的web服务呢?我需要将SOAP调用数据反序列化到java对象 提前感谢我找到了解决方案,下面是它的运行方式 POM.xml <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> &
提前感谢我找到了解决方案,下面是它的运行方式 POM.xml
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<exclusions>
<exclusion>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>cxf-rt-transports-http</artifactId>
<groupId>org.apache.cxf</groupId>
<version>${cxf.version}</version>
</dependency>
<!-- xmlns:jaxws="http://cxf.apache.org/jaxws" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd -->
<jaxws:endpoint address="/mysws"
implementor="com.company.project.MySoapService"
id="mySoapService" />
希望这能帮助有需要的人 添加依赖项
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
实施
package com.smoothexample.cxf.soap.ws.impl;
import com.smoothexample.cxf.soap.ws.AddressSoapService;
import com.smoothexample.dto.Address;
public class AddressSoapServiceImpl implements AddressSoapService {
public Address getAddress() {
return createAddress();
}
private Address createAddress() {
Address address = new Address();
address.setStreetAddress("4800 abc Rd");
address.setCity("abcd");
address.setState("NJ");
address.setCountry("US");
address.setZip("10001");
address.setAddressOptional("addressOptional");
return address;
}
}
请在上查找更多详细信息。您能帮我配置WS-RM enable吗?
<web-app>
<display-name>CXF</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext-cxf.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<?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:jaxws="http://cxf.apache.org/jaxws" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cxf="http://cxf.apache.org/core" xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<task:annotation-driven />
<context:component-scan base-package="com.smoothexample">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Service" />
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Component" />
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Repository" />
</context:component-scan>
<context:annotation-config />
<context:component-scan base-package="com.smoothexample" />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean id="addressSoapService" class="com.smoothexample.cxf.soap.ws.impl.AddressSoapServiceImpl" />
<jaxws:endpoint id="addressEndpointId"
implementorClass="com.smoothexample.cxf.soap.ws.impl.AddressSoapServiceImpl"
implementor="#addressSoapService" address="/addressSoapService">
</jaxws:endpoint>
</beans>
package com.smoothexample.cxf.soap.ws;
import javax.jws.WebService;
import com.smoothexample.dto.Address;
@WebService(endpointInterface = " com.smoothexample.cxf.soap.ws.AddressSoapService",
serviceName = "addressSoapService")
public interface AddressSoapService {
public Address getAddress()
throws Exception;
}
package com.smoothexample.cxf.soap.ws.impl;
import com.smoothexample.cxf.soap.ws.AddressSoapService;
import com.smoothexample.dto.Address;
public class AddressSoapServiceImpl implements AddressSoapService {
public Address getAddress() {
return createAddress();
}
private Address createAddress() {
Address address = new Address();
address.setStreetAddress("4800 abc Rd");
address.setCity("abcd");
address.setState("NJ");
address.setCountry("US");
address.setZip("10001");
address.setAddressOptional("addressOptional");
return address;
}