CXF3.0.1+spring+maven搭建webservice服务
2014-12-05 17:25
525 查看
统一接口:
@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服务创建成功。
相关文章推荐
- 搭建web项目结合spring+cxf的webservice服务
- 搭建web项目结合spring+cxf的webservice服务
- 【Spring_WebService(CXF)】环境的搭建以及服务的暴露
- cxf3.x +spring 3.x(4.x)+ maven 发布webservice 服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- 使用CXF和spring搭建webService服务
- Maven+SpringMVC+CXF整合实现webservice服务的发布与调用
- 搭建web项目结合spring+cxf的webservice服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- 搭建web项目结合spring+cxf的webservice服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- Eclipse+Maven+Spring+CXF 构建webservice 服务
- CXF搭建webService服务器(maven or jar)
- ibatis+spring+cxf+mysql搭建webservice
- 基于Spring和CXF的webservice开发环境搭建
- 在Eclipse中基于Spring+CXF搭建RESTful Web Service的Maven项目
- maven+CXF+Spring+tomcat 开发webservice
- 第三章:Dubbo整合maven+spring+springmvc+mybatis之服务消费搭建
- CXF+Spring 搭建的WebService
- CXF+Spring+REST发布webservice服务