CXF3.0.1+spring+maven搭建webservice服务
来源:互联网 发布:cf刷雷神软件免费版 编辑:程序博客网 时间:2024/06/12 01:19
统一接口:
@WebService
public interface DrugInterfaceService {
public String printMessage(@WebParam(name = "firstName") String firstName,
@WebParam(name = "secondName") String secondName);
}
实现接口:
@WebService(name = "drugService")
public class DrugService implements DrugInterfaceService {
@Override
public String printMessage(String firstName, String secondName) {
return firstName + secondName;
}
}
spring配置文件1:applicationContext-cxf.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:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">
<!-- 服务 -->
<jaxws:endpoint id="drugService" implementor="drugService.services.DrugService"
address="drugService" />
</beans>
spring配置文件2:applicationContext.xml:
<beans>
....
</beans>
web.xml配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml,
/WEB-INF/classes/applicationContext-cxf.xml</param-value>
</context-param><!-- 多个spring配置文件用,分隔-->
<!-- 初始化 CXF SERVLET-->
<servlet>
<servlet-name>CXFServlet</servlet-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>
pom.xml配置:(一定要加这个才行,不然会报错)
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
然后将项目发布到tomcat启动起来,访问http://localhost:8080/drug/drugService?wsdl。
打印出如下:
<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions targetNamespace="http://services.drugService/" name="DrugServiceService" xmlns:ns1="http://interfaceService.drugService/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.drugService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import namespace="http://interfaceService.drugService/" location="http://localhost:8080/drug/drugService?wsdl=DrugInterfaceService.wsdl"> </wsdl:import>
-<wsdl:binding name="DrugServiceServiceSoapBinding" type="ns1:DrugInterfaceService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
-<wsdl:operation name="printMessage">
<soap:operation style="document" soapAction=""/>
-<wsdl:input name="printMessage">
<soap:body use="literal"/>
</wsdl:input>
-<wsdl:output name="printMessageResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-<wsdl:service name="DrugServiceService">
-<wsdl:port name="drugServicePort" binding="tns:DrugServiceServiceSoapBinding">
<soap:address location="http://localhost:8080/drug/drugService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
至此webservice服务创建成功。
@WebService
public interface DrugInterfaceService {
public String printMessage(@WebParam(name = "firstName") String firstName,
@WebParam(name = "secondName") String secondName);
}
实现接口:
@WebService(name = "drugService")
public class DrugService implements DrugInterfaceService {
@Override
public String printMessage(String firstName, String secondName) {
return firstName + secondName;
}
}
spring配置文件1:applicationContext-cxf.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:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">
<!-- 服务 -->
<jaxws:endpoint id="drugService" implementor="drugService.services.DrugService"
address="drugService" />
</beans>
spring配置文件2:applicationContext.xml:
<beans>
....
</beans>
web.xml配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml,
/WEB-INF/classes/applicationContext-cxf.xml</param-value>
</context-param><!-- 多个spring配置文件用,分隔-->
<!-- 初始化 CXF SERVLET-->
<servlet>
<servlet-name>CXFServlet</servlet-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>
pom.xml配置:(一定要加这个才行,不然会报错)
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
然后将项目发布到tomcat启动起来,访问http://localhost:8080/drug/drugService?wsdl。
打印出如下:
<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions targetNamespace="http://services.drugService/" name="DrugServiceService" xmlns:ns1="http://interfaceService.drugService/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.drugService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import namespace="http://interfaceService.drugService/" location="http://localhost:8080/drug/drugService?wsdl=DrugInterfaceService.wsdl"> </wsdl:import>
-<wsdl:binding name="DrugServiceServiceSoapBinding" type="ns1:DrugInterfaceService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
-<wsdl:operation name="printMessage">
<soap:operation style="document" soapAction=""/>
-<wsdl:input name="printMessage">
<soap:body use="literal"/>
</wsdl:input>
-<wsdl:output name="printMessageResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-<wsdl:service name="DrugServiceService">
-<wsdl:port name="drugServicePort" binding="tns:DrugServiceServiceSoapBinding">
<soap:address location="http://localhost:8080/drug/drugService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
至此webservice服务创建成功。
0 0
- CXF3.0.1+spring+maven搭建webservice服务
- 使用cxf3.0.4搭建webservice服务需要的最精简jar包
- 使用cxf3.0.4搭建webservice服务需要的最精简jar包
- Spring整合CXF3.1实现webservice
- spring-ws搭建webservice服务
- cxf3.1.7+spring+maven配置实现记录
- Spring+CXF3.1.3搭建SOAP服务端(一)
- CXF3.0.1以后版本 webService 整合Spring 提示找不到cxf-extension-soap.xml
- maven+spring3+cxf 搭建webservice服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- CXF3.1.8开发与spring集成的webService
- 使用CXF和spring搭建webService服务
- webservice-CXF3.0
- Spring+CXF3.1.3-WSDL2JAVA 搭建SOAP客户端(二)
- Spring+CXF3.1.3-WSIMPORT 搭建SOAP客户端(三)
- maven 搭建spring boot web服务程序
- spring4.1.6+cxf3.0.8的简单WebService案例(maven工程)
- SpringMVC强大的数据绑定(1)——注解式控制器详解
- 第四章总结1
- DOS查看端口占用及杀掉进程命令
- linux oracle 自动备份脚本 保存一周
- 拷贝数据库文件到路径
- CXF3.0.1+spring+maven搭建webservice服务
- android:descendantFocusability用法
- 数据压缩到底在干嘛
- Ubuntu12.04不能连接小米开发,adb devices不能看到设备
- 心是一种念想
- Extjs 列表动态显示
- SpringMVC强大的数据绑定(2)——注解式控制器详解
- 如何解决Hibernate怎么在控制台查看自动生成的建表语句和其他语句?
- 网路编程的中相关函数