8、Web Service-IDEA-jaxws规范下的 spring整合CXF
前提:开发和之前eclipse的开发有很大的不同!
1、服务端的实现
1、新建项目
此时创建的是web项目

2、此时创建的项目是不完整的需要开发人员手动补充完整

3、对文件夹的设置(满满的软件使用方法)

helloService.java
package com.ce.service; import javax.jws.WebService; @WebService
public interface helloService {
public String hello(String name);
}
接口的实现类:
package com.ce.service.impl;
import com.ce.service.helloService; public class helloServiceImpl implements helloService {
@Override
public String hello(String name) {
return "你好 : " + name;
}
}
关键的是web.xml文件的配置:
这里的url-pattern是一个切点(知道就好了)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>cxf</display-name> <servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<!--将作为前缀的一部分-->
<url-pattern>/cr/*</url-pattern>
</servlet-mapping> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </web-app>
spring的配置文件
applicationContext.xml
这里需要引入约束
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
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/spring-context.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schema/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<!--服务地址-->
<jaxws:server address="/hello">
<!--服务类-->
<jaxws:serviceBean>
<bean class="com.ce.service.impl.helloServiceImpl"></bean>
</jaxws:serviceBean>
</jaxws:server>
</beans>
添加tomcat进行运行项目:

在同tomcat文件夹中加入jar(坑位)
否则启动就会立即进行报错


2、客户端
1、新建项目

2、工程目录

3、pom文件的依赖
pom文件的依赖与服务的相同
4、applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
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/spring-context.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schema/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd"> <!--客户端配置-->
<!--
服务地址
服务接口类型
-->
<jaxws:client id="helloService"
serviceClass="com.ce.service.helloService"
address="http://localhost:8082/cr/hello">
</jaxws:client> </beans>
测试类:
package com.ce; import com.ce.service.helloService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Client { //注入对象
@Resource
private com.ce.service.helloService helloService; @Test
public void test(){
//查看接口的代理对象类型
System.out.println(helloService.getClass()); //远程访问服务的的方法
String mr = helloService.hello("Mr");
System.out.println(mr); }
}
此时测试可以得到答案!!!
8、Web Service-IDEA-jaxws规范下的 spring整合CXF的更多相关文章
- 分析下为什么spring 整合mybatis后为啥用不上session缓存
因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...
- 2017年2月16日 分析下为什么spring 整合mybatis后为啥用不上session缓存
因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...
- Web Service 之JAX-WS 与CXF实现
Web Service的实现方式有很多种,本篇介绍的是基于JAX-WS(纯Java)实现的,然后借由CXF工具生成Javabean. 第一步:创建一个Java工程,编写CalService接口,此接口 ...
- Apache CXF实现Web Service(1)——不借助重量级Web容器和Spring实现一个纯的JAX-WS web service
废话少说,先在Eclipse中新建一个Java Project (可以不是WTP的Dynamic Web Project) 选择Java Project 再看pom.xml 我们使用cxf 3.1.4 ...
- 什么情况下应该使用Web Service?
现在我将列举三种情况,在这三种情况下,你将会发现使用Web service会带来极大的好处.此后,我还会举出不应该使用Web service的一些情况. 跨越防火墙的通信 如果你的应用程序有成千上万的 ...
- Web Service(1.8)
“基于 XMLWeb Service 的 Java API”(JAX-WS)通过使用注释来指定与 Web Service 实现相关联的元数据以及简化 Web Service 的开发.注释描述如何将 ...
- 【Java学习笔记】如何写一个简单的Web Service
本Guide利用Eclipse以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程: 1.系统条件: Eclipse Java EE IDE for Web De ...
- Java:Web Service初入门
前言 Web Service技术在我第一次接触,又没有实际使用时完全不理解这是什么.以为是一种类似Spring,Shiro的编程框架.后来渐渐理解,WS(即Web Service缩写)是一种通用的接口 ...
- Web Service学习小结(概念性回忆)-希望你们会喜欢
Web Service的出现带来了很多系统工程直接相互的调用.无疑让代码的隐藏得到了好的封装. Web Service 它的主要的组成要素: SOAP:(Simple Object Access P ...
随机推荐
- 实例-PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别-获取前台公用文-dirname-PHP的"魔术常量"-str_replace
Part1:实例 $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使 ...
- Cookie写入之path的坑
问题 我在/page/index/index.html中向浏览器添加了一个useid的cookie(这里没有指定path), 然后试着从/page/demo/demo.html中取值,发现无法取到, ...
- 图解源码之java锁的获取和释放(AQS)篇
以独占式不公平锁为例,通过5个线程争夺ReentrantLock的过程,图解ReentrantLock源码实现,了解显示锁的工作流程. 任何时刻拿到锁的只有一个线程,未拿到锁的线程会打包成节点(nod ...
- uestc Another LCIS
Another LCIS Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 193 Tried: 2428 Description For a se ...
- 1.springIOC初识
IOC,控制反转,从最浅显的角度来讲就是通过Spring容器来负责创建对象 大体的实现结构 1.首先有一个我们需要运行的类 2.在spring专属的xml配置文件中配置该类 3.启动容器 4.从该容器 ...
- 0 test classes found in package in XXXX
除了参考其他的方法,要注意XXXX位置下是否有空文件夹,删掉.
- svg矢量图标在html中的使用, (知识点:1.通过h5中的css实现点击变色,2.一个svg文件包含多个图标)
svg矢量文件体积小,不变形,比传统的png先进,比现在流行的icon-font灵活.然而在使用过程中还是遇到了很多坑.今天花了一天时间把经验整理出来,以供后来者借鉴.如果您从本文收益,请留言mark ...
- 关于META你知道多少
META标签,是HTML语言head区的一个辅助性标签.在几乎所有的page里,我们都可以看 到类似下面这段html代码: -------------------------------------- ...
- jquery实现除指定区域外点击任何地方隐藏DIV
<!--弹出的表情选择框--> <div class="layui-input-block expression-box"> </div> &l ...
- webstorm 打开后 一直停留在scanning files to index....,或跳出内存不够的提示框
用着有时会这样,超级卡, 网上搜了下,原来如此,记录下,免得忘了. ------------------------- 说明: 在npm install 后,会出现Scanning files to ...