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 ...
随机推荐
- javascript window.opener的用法分析
window.opener 返回的是创建当前窗口的那个窗口的引用 window.opener 的用法 window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接 ...
- Java学习--list,set,Map接口使用
list接口: 泛型:规定list中的元素的类型 /* * * 泛型不能使用基本数据类型(可以使用基本类型的包装类) * */ public void tes ...
- 1、类、封装(私有private、this关键字)
类与对象 对象在需求中的使用 对面向对象有了了解之后,我们来说说在具体问题中如何使用面向对象去分析问题,和如何使用面向对象. 我们把大象装冰箱为例进行分析. 在针对具体的需求,可以使用名词 ...
- 撩课-Java每天5道面试题第14天
101.请解释下 ORM? 对象关系映射(Object Relational Mapping)模式 是一种为了解决面向对象与关系数据库 存在的互不匹配的现象的技术. 简单来说, ORM是通过使用描述对 ...
- 系统分析与设计 homework-1
1.软件工程的定义 软件工程是将系统化.规范化.可度量的方法应用于软件的开发.运营和维护上,也就是将工程方法应用于软件上,并对这些方法的研究. 2.软件危机(software crisis) 软件危机 ...
- Java CountDownLatch解析(下)
写在前面的话 在上一篇CountDownLatch解析中,我们了解了CountDownLatch的简介.CountDownLatch实用场景.CountDownLatch实现原理中的await()方法 ...
- css实现中间文字,两边横线效果
1. vertical-align属性实现效果: vertical-align 属性设置元素的垂直对齐方式. 该属性定义行内元素的基线相对于该元素所在行的基线的垂直对齐.允许指定负长度值和百分比值. ...
- csharp: string Encoding
/// <summary> /// 中文转unicode /// </summary> /// <param name="str"></p ...
- toast, 警告窗
//浮动提示框 1秒后消失 toast(msg, isError, sec) { var div = $('#toast'); div.html(msg); div.css({visibility: ...
- JS 数据容量转换/换算
function diskSize(num){ if (num == 0) return '0 B'; var k = 1024; //设定基础容量大小 var sizeStr = ['B','KB' ...