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 ...
随机推荐
- 使用xml4j xml与字符串之间转换
jar准备:dom4j-2.1.1.jar jaxen-1.1.6.jar jaxen/jaxen/ Maven依赖写法 <dependency> <groupId>jaxe ...
- HTML骨架详解
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- K:顺序表和链表的比较
顺序表和链表是线性表的两种基本实现形式(链表还有多种变化形式),对于这两种实现方式,没有一种方法可以称是最好的,他们各自有着各自的特点和优缺点,适用于不同的应用场景. 与顺序表相比,链表较为灵活, ...
- 在弹框中获取foreach中遍历的id值,并传递给地址栏。
1.php有时候我们需要再弹框中获取foreach中遍历的数据(例如id),在弹框中点击按钮并传递给地址栏跳转.那么应该怎么做呢. 2. 点击取现按钮,如果没有设置密码->弹框 3. 点击去设置 ...
- JAVASE(说出ArrayList,LinkedList的储存性能和特性)
说出ArrayList,和LinkedList的储存性能和特性? 答: ## ArrayList采用的是数组形式来保存对象的,这种方式将对象放在连续的位置中,优点是索引读取快,从最后插入和删除元素速 ...
- PHP读取Excel类文件
想要使用PHP读取Excel文件必然要用到PHPExcel开源类库,网上资源应该挺多的.但是每一种的操作必然都是不同的,可原理应该都是大同小异. 这个文件夹里包含的就是PHPExcel类文件,在外面还 ...
- 微服务架构之spring cloud eureka
Spring Cloud Eureka是spring cloud的核心组件,负责服务治理功能,起到中心枢纽作用,其它组件都依赖eureka来获取服务,然后再根据项目需求实现自己的业务,eureka在整 ...
- Recovering InnoDB table from an .ibd file.
Recovering an InnoDB table from only an .ibd file. Sometime you may need to recover a table when all ...
- C#多线程顺序依赖执行控制
在开发过程中,经常需要多个任务并行的执行的场景,同时任务之间又需要先后依赖的关系.针对这样的处理逻辑,通常会采用多线程的程序模型来实现. 比如A.B.C三个线程,A和B需要同时启动,并行处理,且B需要 ...
- TPS和事务响应时间的关系、计算公式 (转)
例子:一个高速路有10个入口,每个入口每秒钟只能进1辆车1.请问1秒钟最多能进几辆车? TPS=102.每辆车需要多长时间进行响应? reponse time = 13.改成20辆车,每秒能进 ...