webservice服务器框架配置文件,java web项目(spring项目)中集成webservice ,实现对外开放接口...

什么是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

java web 手动部署项目步骤

java Web 手动部署项目步骤 1 在tomcat下面的webapps下面建立需要部署的文件夹(eg:demo);2 在demo下建立 WEB-INF WETA-INF src 文件夹;3 在sr ...

细说shiro之五:在spring框架中集成shiro

官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下:

spring boot 2 集成JWT实现api接口认证

JSON Web Token(JWT)是目前流行的跨域身份验证解决方案.官网:https://jwt.io/本文使用spring boot 2 集成JWT实现api接口验证. 一.JWT的数据结构 J ...

传统Java Web(非Spring Boot)、非Java语言项目接入Spring Cloud方案

技术架构在向spring Cloud转型时,一定会有一些年代较久远的项目,代码已变成天书,这时就希望能在不大规模重构的前提下将这些传统应用接入到Spring Cloud架构体系中作为一个服务以供其它项 ...

传统Java Web(非Spring Boot)、非Java语言项目接入Spring Cloud方案--temp

技术架构在向spring Cloud转型时,一定会有一些年代较久远的项目,代码已变成天书,这时就希望能在不大规模重构的前提下将这些传统应用接入到Spring Cloud架构体系中作为一个服务以供其它项 ...

java web:在eclipse中如何创建java web 项目

Eclipse创建java web工程 eclipse版本:eclipse-jee-4.5-win32-x64 tomcat版本:apache-tomcat-7.0.63-windows-x64 jd ...

Spring Boot中集成Spring Security 专题

check to see if spring security is applied that the appropriate resources are permitted: @Configurat ...

使用Logstash同步数据至Elasticsearch,Spring Boot中集成Elasticsearch实现搜索

安装logstash.同步数据至ElasticSearch 为什么使用logstash来同步,CSDN上有一篇文章简要的分析了以下几种同步工具的优缺点:https://blog.csdn.net/la ...

JAVA学习3:Eclipse中集成Tomcat

问题: 很多时候在Eclipse中启动Tmocat后,不能访问本机的localhost:8080主页,并且其他项目也不能访问. 原因: 打开Tomcat下的webapp后也找补到项目目录,这是因为Ec ...

随机推荐

git rebase与 git合并(error: failed to push some refs to)解决方法

1.遇到的问题 本地有一个git仓库,在github上新建了一个空的仓库,但是更新了REWADME.md的信息,即在github上多了一个提交. 关联远程仓库,操作顺序如下: git remote a ...

Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)(一)

Flume 1.7.0 User Guide Introduction(简介) Overview(综述) System Requirements(系统需求) Architecture(架构) Data ...

ACM/ICPC 之 DFS求解欧拉通路路径(POJ2337)

判断是欧拉通路后,DFS简单剪枝求解字典序最小的欧拉通路路径 //Time:16Ms Memory:228K #include #include

.NET 验证码/验证图片

/// /// 验证码类 /// public class Rand { #region 生成随机数字 ///

ASP.NET基础笔记

MSDN:                                                                                                ...

CSS布局基础

(初级)css布局 一.单列布局1.基础知识块级元素 div p ul li dl dt 行级元素 img span input strong同一行显示.无换行2.盒子模型盒子模型 (边框border ...

密码强度应用(js)

《asp.net mvc3 高级编程》第四章 模型

一,建立简单的Model 在Models文件夹上右击鼠标,选择“添加”,“类”,如下图所示: 建立三类相关联的类代码如下: public class Album { public virtual in ...

AStar算法()

把网上的AStar算法的论述自己实现了一遍,一开始只是最基础的实现.当然,现在AStar算法已经演变出了各种优化的版本,这篇也会基于各种优化不断的更新. 如果对算法不熟悉可以看下Stanford的这篇 ...

C# 获取汉字拼音首字母/全拼

最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精   本节探讨C#获取汉字拼音首字母的方法: 代码类东西, ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值