spring 整合webservice

pom.xml文件

	<dependencies>
<!-- CXF WS开发 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<port>9998</port>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

  web.xml文件

 <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>
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

  applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!-- serviceClass 服务接口
address 服务访问地址
-->
<jaxws:server id="userService" address="/userService"
serviceClass="com.baidu.service.UserService">
<jaxws:serviceBean>
<bean class="com.baidu.service.imp.UserServiceImp" />
</jaxws:serviceBean>
</jaxws:server> </beans>

  

包结构

  UserService接口

package com.baidu.service;

import javax.jws.WebMethod;
import javax.jws.WebService; import com.baidu.domain.User; @WebService
public interface UserService {
@WebMethod
public User get(Integer id);
@WebMethod
public void eat();
}

  UserServiceImp实现类

package com.baidu.service.imp;

import javax.jws.WebMethod;
import javax.jws.WebService; import com.baidu.domain.User;
import com.baidu.service.UserService;
@WebService
public class UserServiceImp implements UserService { public User get(Integer id) {
if(id==1){
User u=new User();
u.setId(2);
u.setName("张三");
return u;
}
return null;
} @Override
public void eat() {
System.out.println("123"); } }

  新建一个maven web project项目

pom.xml文件不变

applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!--
address 客户端访问服务路径
serviceClass 配置接口
serviceBean 配置实现类 -->
<jaxws:client id="userServiceClient"
serviceClass="com.baidu.service.UserService"
address="http://localhost:9998/werservicespring/services/userService" >
<!-- 来源消息拦截器
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</jaxws:inInterceptors> -->
<!-- 输出消息拦截器
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
</jaxws:outInterceptors>-->
</jaxws:client> </beans>  

在测试之前需要创建接口  包结构也需要一样

package com.baidu.service;

import javax.jws.WebMethod;
import javax.jws.WebService; import com.baidu.domain.User; @WebService
public interface UserService {
@WebMethod
public User get(Integer id);
@WebMethod
public void eat();
}

  

测试类

package com.baidu.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baidu.domain.User;
import com.baidu.service.UserService; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class Test01 {
@Autowired
private UserService userService;
@Test
public void test01(){
//userService.eat();
User user = userService.get(1);
System.out.println(user);
}
}

  

webService之helloword(web)的更多相关文章

  1. webservice之helloword(web)rs

    spring整合webservice 1.pom.xml文件 <dependencies> <!-- cxf 进行rs开发 必须导入 --> <dependency> ...

  2. Python开发WebService:REST,web.py,eurasia,Django

    Python开发WebService:REST,web.py,eurasia,Django 博客分类: Python PythonRESTWebWebServiceDjango  对于今天的WebSe ...

  3. webService之helloword(java)rs

    webservice之rs(helloworld) 1.pom.xml文件 <dependencies> <!-- 使用CXF RS开发 --> <dependency& ...

  4. webService之helloword(java)

    webservice 远程数据交互技术 1.导入jar包(如果是 maven项目导入项目坐标) 2.创建服务 3.测试服务 我们使用maven来做测试服务 pom.xml文件 <project ...

  5. 用.NET WebService Studio调试Web Service解决SOAPAction的问题

    话说是这样的,这两天开发一个短信发送功能,客户给了一个 Web Service 地址(没有文档),让我调用就可以发送了, 我在VS 2013添加了服务引用,一切正常,可是执行代理方法时,怎么都报错 R ...

  6. 翻译-使用Spring WebService生成SOAP Web Service

    原文链接:http://spring.io/guides/gs/producing-web-service/ 生成SOAP web service 该指南将带领你使用Spring创建一个基于SOAP的 ...

  7. 用C#通过反射实现动态调用WebService 告别Web引用

    我们都知道,调用WebService可以在工程中对WebService地址进行WEB引用,但是这确实很不方便.我想能够利用配置文件灵活调用WebService.如何实现呢? 用C#通过反射实现动态调用 ...

  8. Web.config中设置启用webservice远程调试访问

    在.NET 中已经默认将webservice的远程调试功能关闭,有的时候我们需要远程调试程序的时候,就需要打开此功能我们只需在webservice的项目的中添web.config的<system ...

  9. Web.config中设置启用webservice远程调试访问 参数看不到

    <system.web><compilation debug="true" /> <!--begin启用webservice远程访问--> &l ...

随机推荐

  1. mysql备份数据库出错mysqldump: [ERROR] unknown option '--no-beep'

    公司数据库前一版本是部署在windows上面的,由于业务需要,迁移到linux,之前一段脚本在windows下使用定时任务执行正常. mysqldump -uzzz -pxxxx --opt --de ...

  2. bloomfilter 以及count min sketch

    bloomfilter http://blog.csdn.net/v_july_v/article/details/6685894 count min sketch http://www.cnblog ...

  3. Java中关键字static的使用

    static 关键字 1).static只能修饰成员变量或成员方法,所有非静态是对象相关的,所有静态是类相关的. 2)被static修饰的成员变量成员方法独立于该类的任何对象,它不依赖类的特定的实例, ...

  4. Nowcoder OI赛制测试2 F 假的数学题 - 斯特林公式 + 二分

    Description 给定$X$, 找到最小的$N$ 使得$N! > X^X$ 数据范围:  $x <= 1e11$ Solution $X^X$ 太大, 高精也存不过, 所以取对数 : ...

  5. MFC动态按钮的创建及其消息响应(自定义消息)

    动态按钮(多个)的创建: 1.在类中声明并定义按钮控件的ID #define IDC_D_BTN 10000 2.在类的OnInitDialog()函数中动态创建按钮(建立按钮对象时最好建立对象的指针 ...

  6. mysql 设置用户并授权

    一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指 ...

  7. 2017/2/12:springMVC的简单文件上传跟拦截器

    1.写文件上传的界面jsp代码如下重点为文件上传标签的类型 2.写登录成功跟失败的界面:成功自己写 3.写springMVC的文件上传的controller的方法 4.最后一步配置spring-ser ...

  8. mysqldb mysql_config

    在安装mysqldb Python的时候会用到mysql_config,但是正常安装的MySQL环境下是没有这个文件的,这个文件在Linux下是可执行文件,所以需要到mysql官方网站上下载MySQL ...

  9. 34、iOS App图标和启动画面尺寸

    注意:iOS所有图标的圆角效果由系统生成,给到的图标本身不能是圆角的. 1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone ...

  10. apache ab工具

    Apache ab并发负载压力测试   ab命令原理 Apache的ab命令模拟多线程并发请求,测试服务器负载压力,也可以测试nginx.lighthttp.IIS等其它Web服务器的压力. ab命令 ...