前提:开发和之前eclipse的开发有很大的不同!

1、服务端的实现

1、新建项目

此时创建的是web项目

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

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

4、类:
接口类
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的更多相关文章

  1. 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  2. 2017年2月16日 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  3. Web Service 之JAX-WS 与CXF实现

    Web Service的实现方式有很多种,本篇介绍的是基于JAX-WS(纯Java)实现的,然后借由CXF工具生成Javabean. 第一步:创建一个Java工程,编写CalService接口,此接口 ...

  4. 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 ...

  5. 什么情况下应该使用Web Service?

    现在我将列举三种情况,在这三种情况下,你将会发现使用Web service会带来极大的好处.此后,我还会举出不应该使用Web service的一些情况. 跨越防火墙的通信 如果你的应用程序有成千上万的 ...

  6. Web Service(1.8)

      “基于 XMLWeb Service 的 Java API”(JAX-WS)通过使用注释来指定与 Web Service 实现相关联的元数据以及简化 Web Service 的开发.注释描述如何将 ...

  7. 【Java学习笔记】如何写一个简单的Web Service

    本Guide利用Eclipse以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程: 1.系统条件: Eclipse Java EE IDE for Web De ...

  8. Java:Web Service初入门

    前言 Web Service技术在我第一次接触,又没有实际使用时完全不理解这是什么.以为是一种类似Spring,Shiro的编程框架.后来渐渐理解,WS(即Web Service缩写)是一种通用的接口 ...

  9. Web Service学习小结(概念性回忆)-希望你们会喜欢

    Web Service的出现带来了很多系统工程直接相互的调用.无疑让代码的隐藏得到了好的封装. Web  Service 它的主要的组成要素: SOAP:(Simple Object Access P ...

随机推荐

  1. Dapper扩展

    using Dapper; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using Sy ...

  2. 撩课-Java每天5道面试题第18天

    121.描述Struts2的工作原理 客户端发送请求--> 请求经过一系列过滤器-> FilterDispatcher通过 ActionMapper来决定这个Reques t需要调用哪个A ...

  3. laravel开发之-安装汉化语言包

    第一种方法: 1.输入命令:composer require "overtrue/laravel-lang:dev-master" 2.将config/app.php中命令“Ill ...

  4. javascript 获取服务时间

    用到了jquery的ajax方法,ajax自己写也可以. 具体用法 var setId = setInterval(function(){ var xhr = $.ajax({ type: 'HEAD ...

  5. Oracle 通过出生日期计算年龄

    方法一: SELECT TRUNC(months_between(sysdate, birth)/12) AS age from mytable 方法二: select TRUNC((to_char( ...

  6. linux 查看在线服务进程

    输入命令:netstat -ltunp  注意,这个-与l之间是没有空格的 要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程, 而ps命令(Process Status)就 ...

  7. PowerDNS Authoritative Server 3.3 发布

    PowerDNS Authoritative Server 3.3 发布,该版本改进了不同验证器的交互操作,修复了不少 bug. PowerDNS Authoritative Server (PDNS ...

  8. GitHub初步探索-1-使用本地代码管理工具,简化上传的过程

    使用GitHub对于我们写Java的同志们来说是一个非常好的代码存储的方式,但是因为是全英文的,操作起来有一点复杂,所以我不是经常使用 ,但是最近代码越敲越多,再加上老师要求,希望使用比较简单的方法来 ...

  9. 阅读《大道至简第一章》读后感 (java 伪代码)

         通读大道至简第一章愚公移山,可以将其看做一个完整的工程,首先是创建工程的原因,需求:“惩山北之塞,出入之迂”,而后是团队之间的商议:“聚室而谋曰”,然后确定工程的目标:“毕力平险,指通豫南, ...

  10. C# 元素组合算法

    class Program { static void Main(string[] args) { string[] a = { "A", "B", " ...