当前位置: 首页 > news >正文

信息平台网站模板深圳网站建设优化

信息平台网站模板,深圳网站建设优化,专业网站建设咨询,wordpress get tags什么是WebService?webService小示例 点此了解下面进入正题:Javaweb项目(spring项目)中集成webservice ,实现对外开放接口步骤:准备:采用与spring兼容性较好的cxf来实现选择zip格式下载,解压后的lib目录下的jar需要最少的jar如下:cxf-2.3.3.jargeronimo-annotation_1.0_spec-1.…

什么是WebService?webService小示例 点此了解

下面进入正题:

Javaweb项目(spring项目)中集成webservice ,实现对外开放接口步骤:

准备:

采用与spring兼容性较好的cxf来实现

选择zip格式下载,解压后的lib目录下的jar

需要最少的jar如下:

cxf-2.3.3.jar

geronimo-annotation_1.0_spec-1.1.1.jar

geronimo-jaxws_2.2_spec-1.0.jar

geronimo-stax-api_1.0_spec-1.0.1.jar

geronimo-ws-metadata_2.0_spec-1.1.3.jar

jaxb-api-2.2.1.jar

jaxb-impl-2.2.1.1.jar

neethi-2.0.4.jar

wsdl4j-1.6.2.jar

XmlSchema-1.4.7.jar

wstx-asl-3.2.9.jar

一:创建webservice服务器

1)创建一个服务接口

package com.service;

import javax.jws.WebParam;

import javax.jws.WebService;

@WebService

public interface IHelloWorld {

public String sayHello(@WebParam(name = "arg0") String text);

}

2)是接口实现类

package com.service.impl;

import javax.jws.WebService;

import com.service.IHelloWorld;

@WebService(endpointInterface = "com.service.IHelloWorld")

public class HelloWorldImpl implements IHelloWorld {

public String sayHello(String text) {

return "Hello : " + text;

}

}

3)创建spring配置文件,将服务类加入到容器中

webservice.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xmlns:cxf="http://cxf.apache.org/core"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd">

在web.xml中添加webservice.xml配置文件

contextConfigLocation

/WEB-INF/webservice.xml

4)在web.xml中加入cxf servlet

CXF Servlet

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

/webservice/*

至此,webservice服务器就创建好了,

在浏览器中访问:http://localhost:8080/test/webservice/HelloWorld?wsdl,(test是项目名称)。如果出现了类似与

。。。。

就配置成功了。

接下来贴几个运行时的错误解决方法

1:webservice.xml中提示cxf.xml,cxf-servlet.xml not found,我在上面写的路径是classpath*:META-INF/cxf/cxf.xml,这里的classpath后面还跟了一个“*”符号,没加符号表示只在类路径下查找cxf.xml文件,加了号表示不仅在类路径下查找xml文件,还在jar包中查找xml文件。所以当我们在项目类路径下没有假如cxf.xml等配置文件时,就一定要在classpath后加*,这样spring容器才会去所加入的jar包中找。

2:假如cxf servlet时,映射路径不要写成/*,否则会出现访问不了项目主页的情况,可以写成/webservice/*或者别的项目中没有使用过的路径来作为cxf servlet的请求路径。

二:创建webservice客户端

客户端可以和服务器放在同一个项目中用来测试,也可以新建一个Java项目来进行测试。

新建一个Java项目测试时,要假如对应的jar包,跟服务器一样,使用spring还要假如spring jar包。

我在这里新建一个项目,依旧使用spring来测试

1)首先要创建一个和服务器端一样的服务接口,(如果客户端和服务器端在同一个项目中则可以省略这步)

package com.service;

import javax.jws.WebParam;

import javax.jws.WebService;

@WebService

public interface IHelloWorld {

public String sayHello(@WebParam(name = "arg0") String text);

}

2)创建spring-client.xml,

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schema/jaxws.xsd">

3)测试类

package com.test;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.service.IHelloWorld;

public class Test {

public static void main(String[] args) {

ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-client.xml");

IHelloWorld client = (IHelloWorld) ctx.getBean("client");

String result = client.sayHello("你好!");

System.out.println(result);

}

}

运行成功后显示

Hello:你好!

文章参考: http://www.open-open.com/lib/view/open1405929509210.html

http://www.lbrq.cn/news/2580517.html

相关文章:

  • wordpress插件video playeseo网课培训
  • 忻州做网站北京互联网公司有哪些
  • 简单企业网站建设软文写作技巧及范文
  • 网站首页效果图潍坊网站开发公司
  • 网络营销方式ppt搜索引擎环境优化
  • 网站模板没有html文件下载搜索引擎广告图片
  • 怎么做游戏网站编辑关键词优化是怎样收费的
  • 毕业设计代做网站有哪些百度权重域名
  • 企业网站建设网页北京seo营销公司
  • 网站排名带照片怎么做最好的搜索引擎
  • 服装公司网站建设方案河南seo
  • 小型手机网站建设多少钱磁力搜索引擎下载
  • 成都大型网站设计公司网站seo置顶 乐云践新专家
  • wordpress页脚改颜色网站关键词排名优化推广软件
  • 个人网站怎么做口碑站长之家seo工具
  • 国外文本排版设计网站企业品牌推广营销方案
  • excel如何做超链接网站不花钱网站推广
  • 足球亚洲排名最新排名seo的基本内容
  • 天河网站建设专家网页制作成品
  • 佛山网站建设外包站长网站查询
  • 时尚手表网站百度指数手机版
  • 单页网站内链接沧州网站建设公司
  • 织梦网站搜索怎么做营销策略分析论文
  • 怎么做报名网站东莞网络营销渠道
  • 郑州企业建站详情百度霸屏推广一般多少钱
  • 安徽餐饮网站建设湖南今日新闻最新头条
  • 郑州网站建设自动点击器软件
  • 做网站时版权怎么写怎么制作个人网页
  • 专门做淘宝优惠券的网站网站建设软件
  • 备案可以不关闭网站吗今日热搜新闻头条
  • 选择排序原理与C语言实现详解
  • Redis+Lua的分布式限流器
  • elk快速部署、集成、调优
  • k8s日志收集
  • 知识蒸馏 - 基于KL散度的知识蒸馏 HelloWorld 示例
  • 《软件测试与质量控制》实验报告一 测试用例设计