webservice与spring整合发布后台服务
来源:互联网 发布:在ubuntu安装虚拟机 编辑:程序博客网 时间:2024/05/16 15:06
现在开发一般都会用主流的架构SSH,当然有时候在我们所要实现的功能中需要调用别人开发的功能,比方说查询天气情况,而此时就需要用SSH去调用查询天气的webService服务了。所以webService和SSH之间的整合是必然的。当然我们可以调用别人发布的webService,也可以自己发布webService功能以供别人调用。在这节中我们先来说说如何发布webService吧。其实很简单的,也就是以下几个步骤:
1、将cxf和spring相关jar包考入到lib下面,大致有下面这些(红框是spring的,外面的是cxf的):
2、编写webService接口及代码
1)接口
package com.tgb.web.webservice;
import javax.jws.WebService;@WebServicepublic interface HelloWorld {public String sayHi(String str);}
2)实现类:
package com.tgb.web.webservice.impl;
3、在web.xml配置文件中加入spring和cxf的配置import java.util.Date;import javax.jws.WebService;import com.tgb.web.webservice.HelloWorld;@WebService(endpointInterface="com.tgb.web.webservice.HelloWorld",serviceName="HelloWorld")public class HelloWorldBean implements HelloWorld {@Overridepublic String sayHi(String str) {return "hello,"+str+",现在时间是:"+new Date();}}
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 在Web Server启动的时候将BeanFactory放到ServletContext中 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- CXF配置 --> <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>/cxfservice/*</url-pattern> </servlet-mapping> </web-app>
4、在applicationContext.xml配置文件中加入cxf的scahme
<?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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 导入CXF的配置文件 --> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <bean id="helloService" class="com.tgb.web.webservice.impl.HelloWorldWs"> </bean> <!-- implementor指定webService的服务提供者。支持两种形式 A:直接给定服务器提供者的类名 B:设置为容器中一个Bean,采用注入方式 --> <jaxws:endpoint implementor="#helloService" address="/fkjava" > <!-- 配置in拦截器 <jaxws:inInterceptors> <ref bean="org.apache.cxf.interceptor.LoggingInInterceptor"/> <ref bean="com.tgb.web.util.AuthInterceptor"/> </jaxws:inInterceptors> --> <!-- 配置out拦截器 <jaxws:outInterceptors> <ref bean="outLoggingInterceptor"/> </jaxws:outInterceptors> --> </jaxws:endpoint></beans>
5、将web程序发布到服务器(如tomcat)上,后访问地址:http://***:8080/cxf_spring/fkservice/fkjava?wsdl。客户端则和以前的一样,再此不在重复
1 0
- webservice与spring整合发布后台服务
- 7、CXF与Spring整合,发布WebService服务
- webservice 整合spring 使用接口发布服务
- (四)CXF整合Spring发布WebService服务
- Spring中整合Xfire发布webservice服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF配置WebService服务发布
- Spring整合CXF之发布WebService服务
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- CXF与Spring整合开发WebService服务
- 8、CXF与Spring整合发布http rest 风格的WebService服务
- WebService的CXF框架与Spring的整合发布服务入门
- webservice--CXF+Spring整合发布SOAP协议的服务
- webservice--CXF+Spring整合发布REST的服务
- WebService之CXF整合Spring框架发布REST服务
- Spring整合CXF发布WebService
- 如何使用java语言遍历数组
- Go语言截取字符串
- 自定义控件三部曲之绘图篇(十一)——Paint之setXfermode(二)
- poj3693 Maximum repetition substring (后缀数组+rmq)
- 基础卷_异常篇 第11集 异常--总结2补充
- webservice与spring整合发布后台服务
- 关于形如--error LNK2005: xxx 已经在 msvcrtd.lib ( MSVCR90D.dll ) 中定义--的问题分析解决
- STL容器元素应满足的条件
- PAT-B 1029. 旧键盘
- boot2docker.iso无法下载
- vtk实战(三十九)——读取PNG数据
- Reverse Vowels of a String
- OpenGLES::体验OpenGL ES的乐趣
- 1.Python操作Redis:键(Key)