webservice jar 下载: http://download.csdn.net/download/knight_black_bob/9186507
webservice server 下载:http://download.csdn.net/download/knight_black_bob/9186521
webservice client 下载:http://download.csdn.net/download/knight_black_bob/9186517
综合下载:http://download.csdn.net/download/knight_black_bob/9186535
user 实例 来自 :
springmvc+mybatis+mysql 自动生成代码 http://knight-black-bob.iteye.com/blog/2208162
0 准备工作 jar 下载
cxf-2.6.1.jar geronimo-annotation_1.0_spec-1.1.1.jar geronimo-jaxws_2.2_spec-1.1.jar geronimo-ws-metadata_2.0_spec-1.1.3.jar neethi-3.0.2.jar slf4j-api-1.6.2.jar wsdl4j-1.6.2.jar xmlschema-core-2.0.2.jar jetty-continuation-7.5.4.v20111024.jar jetty-http-7.5.4.v20111024.jar jetty-io-7.5.4.v20111024.jar jetty-server-7.5.4.v20111024.jar jetty-util-7.5.4.v20111024.jar
1.webservice server
1.1 service 接口
package cn.com.baoy.service; import java.util.List; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import org.springframework.stereotype.Service; import cn.com.baoy.bean.User; /** * @author baoyou E-mail:curiousby@163.com * @version 创建时间:2015年10月13日 上午11:13:28 * des: */ @WebService @SOAPBinding(style = Style.RPC) public interface UserService { public String sayHello(String string); public List<User> allUser(); public void delUser(Integer userId); public User user(Integer userId); public void updateUser(User user); public void addUser(User user); }
1.2 serviceimpl 接口实现
package cn.com.baoy.service.impl; import java.util.List; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import cn.com.baoy.bean.User; import cn.com.baoy.dao.UserDao; import cn.com.baoy.service.UserService; @Service @WebService(endpointInterface="cn.com.baoy.service.UserService", serviceName="UserService") @SOAPBinding(style = Style.RPC) public class UserServiceImpl implements UserService { @Autowired UserDao dao; public String sayHello(String string){ return "test : "+string; } public List<User> allUser(){ return dao.allUser(); } public void delUser(Integer userId){ dao.delUser(userId); } public User user(Integer userId){ return dao.user(userId); } public void updateUser(User user){ dao.updateUser(user); } public void addUser(User user){ dao.addUser(user); } }
1.3application-cxf.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" default-autowire="byName"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <bean id="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <jaxws:endpoint implementor="cn.com.baoy.service.impl.UserServiceImpl" address="/userService"></jaxws:endpoint> </beans>
1.4 test-servlet
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd " default-autowire="byName"> <!-- 数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!-- 自动扫描controller bean,把作了注解的类转换为bean --> <context:component-scan base-package="cn.com.baoy" /> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 --> <!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="" p:suffix=".jsp"> <property name="order" value="0" /> </bean> --> <!-- 创建SqlSessionFactory,同时指定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath*:cn/com/baoy/mapper/*.xml" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.com.baoy.dao" /> </bean> </beans>
1.5web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>back/jsp/main.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/application-cxf.xml /WEB-INF/test-servlet.xml</param-value> </context-param> <servlet> <servlet-name>test</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/WebService/*</url-pattern> </servlet-mapping> </web-app>
接口发布成功 后
2.0 测试发布接口程序
package cn.com.baoy; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import cn.com.baoy.service.UserService; public class WSTest { public static void main(String[] args) { //创建WebService客户端代理工厂 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); //注册WebService接口 factory.setServiceClass(UserService.class); //设置WebService地址 factory.setAddress("http://localhost:8080/webserviceserver/WebService/userService"); UserService userService = (UserService)factory.create(); System.out.println("invoke webservice..."); System.out.println("message context is:"+userService.sayHello("baoyou")); System.out.println("message context is:"+userService.user(7).getUserName()); } }
接口测试 结果:
3 webservice client
3.1 接口定义
package cn.com.baoy.service; import java.util.List; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import org.springframework.stereotype.Service; import cn.com.baoy.bean.User; /** * @author baoyou E-mail:curiousby@163.com * @version 创建时间:2015年10月13日 上午11:13:28 * des: */ @WebService @SOAPBinding(style=SOAPBinding.Style.RPC) public interface UserService { public String sayHello(String string); public List<User> allUser(); public void delUser(Integer userId); public User user(Integer userId); public void updateUser(User user); public void addUser(User user); }
3.2
package cn.com.baoy.controller; import java.util.List; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import cn.com.baoy.bean.User; import cn.com.baoy.service.UserService; @Controller public class UserController { @Autowired UserService userService; @RequestMapping(value = "/userView.do") public String userView(ModelMap modelMap,String pageNo, String choice, HttpSession session){ List<User> userList = userService.allUser(); modelMap.put("userList", userList); return "back/jsp/user/userView"; } @RequestMapping(value = "/userDel{userId}.do") public String userDel(@PathVariable("userId")int userId ,ModelMap modelMap,String pageNo, String choice, HttpSession session){ userService.delUser(userId); String message1="删除成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; } @RequestMapping(value ="/userGoAdd.do") public String userGoAdd(ModelMap modelMap,String pageNo, String choice, HttpSession session){ return "back/jsp/user/userAdd"; } @RequestMapping(value = "/userAdd.do",method=RequestMethod.POST) public String userAdd(User form,ModelMap modelMap,String pageNo, String choice, HttpSession session){ userService.addUser(form); String message1="添加成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; } @RequestMapping(value = "/userGoUpdate{userId}.do") public String userGoUpdate(@PathVariable("userId")int userId ,ModelMap modelMap,String pageNo, String choice, HttpSession session){ User user = userService.user(userId); modelMap.put("user", user); return "back/jsp/user/userUpdate"; } @RequestMapping(value = "/userUpdate.do",method=RequestMethod.POST) public String userUpdate(User form,ModelMap modelMap,String pageNo, String choice, HttpSession session){ userService.updateUser(form); String message1="修改成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; } }
3.3 application-service.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <jaxws:client id="userService" serviceClass="cn.com.baoy.service.UserService" address="http://localhost:8080/webserviceserver/WebService/userService"/> </beans>
3.4 web.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd " default-autowire="byName"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/config.properties</value> </property> </bean> <!-- 数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!-- 自动扫描controller bean,把作了注解的类转换为bean --> <context:component-scan base-package="cn.com.baoy" /> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="" p:suffix=".jsp"> <property name="order" value="0" /> </bean> <!-- 创建SqlSessionFactory,同时指定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath*:cn/com/baoy/mapper/*.xml" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.com.baoy.dao" /> </bean> </beans>
测试 跑通程序
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
最近开发了一个基于ssm(Spring+SpringMVC+Mybatis)的项目,整合了CXF发布webservice。现在来分享项目源码,希望能帮助到有需要的朋友。
http://knight-black-bob.iteye.com/blog/2249625 webservice client (springmvc +mybatis+mysql +cxf )
http://knight-black-bob.iteye.com/blog/2249625 webservice server (springmvc +mybatis+mysql +cxf )
蛮简陋的一个项目,适合新手使用。 这是一个包含简单登录和查询的Web项目,内附有一个表sql文件和两个java项目。...WS_Client是客户端,是一个project项目,内部有一个WebService的测试类,用来测试从服务端取得数据
学习spring 框架 和 cxf webservice接口等必备,接口 restful webservice
最近开发了一个基于ssm(Spring+SpringMVC+Mybatis)的项目,整合了CXF发布webservice。现在来分享项目逻辑和一下开发经验。 当然,开发这个项目的时候,借鉴网上一个博客的经验,主要是ssm的搭建过程,贴出博客地址...
如题,主要是以Cxf Webservice为主,数据库使用mysql,自己可以根据需要自己创建,也可以直接将AmUserServiceImpl类中的数据库操作该为普通java代码。另外客户端调用代码在Controller包下面
在springMvc+mybaties web项目基础上增加CXF webService实现
项目框架: spring+springmvc+mybatis 是否使用maven: 使用 数据库:oracle 使用了cxf 同时实现了 RESTful WebService --项目启动后访问地址 ...
使用cxf、spring构建的rest风格webservice,其他相关技术springmvc、mybatis、druid等。代码中使用的数据库为sybase,请根据实际环境更改,需修改pom中引用的数据库驱动,依照entity类的属性建对应表,并修改config....
NULL 博文链接:https://showlike.iteye.com/blog/1005822
Maven+Spring+Spring MVC+MyBatis+MySQL整合SSM框架; 已集成activeMq;cxf webservice;邮件;
SSM+cxf+log4j整合框架;springmvc+spring+mybatis整合开发,内部集成webservice技术,采用cxf框架进行实现,log4j进行日志记录
springmvc+mybatis+cxf+客户端+服务器端+soap+rest方式+内部有数据库
使用spring集成cxf,在两个web ...server端使用spring+springmvc+mybatis+cxf,client端使用struts2+spring+hibernate+cxf 两个工程均为myeclipse project,包含所有除myeclipse自带以外所有jar 内附 使用文档,数据库脚本
spring,springMvc,mybatis整合,cxf发布webservice,quartz定时器
项目使用的是mybatis分页拦截器实现的分页,该链接是一个单表分页,如果想联表分页请将mapping中返回值类型改为map,同时进行联表查询, 谢谢大家 有疑问的地方可以留言或者发我邮箱sl166199@163.com
1. Springmvc + Mybatis集成、SpringSecurity权限控制、Spring AOP事务处理。 2. Wink Rest服务、Webservice服务:jaxws、CXF等 3. IO 流上传下载文件,多线程操作 4. 发送邮件,配置邮件服务器,发基于html、纯...
webservice clinet server jar http://knight-black-bob.iteye.com/blog/2249625 (springmvc +mybatis+mysql +cxf )
使用springmvc+mybatis整合cxf,完成添加订单以及添加订单详情功能