(webservice+cxf+mybatis+mysql+springmvc) webservice + cxf 能够跑起来的cxf ,来这里,,

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:   webservice jar 下载:  http://download.csdn.net/download/knight_black_bob/9186507 webservice server  下载:http://download.

 

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&amp;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&amp;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捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
19天前
|
缓存 前端开发 Java
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
Soring Boot的起步依赖、启动流程、自动装配、常用的注解、Spring MVC的执行流程、对MVC的理解、RestFull风格、为什么service层要写接口、MyBatis的缓存机制、$和#有什么区别、resultType和resultMap区别、cookie和session的区别是什么?session的工作原理
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
|
2月前
|
Java 关系型数据库 数据库连接
|
4月前
|
Java 关系型数据库 MySQL
Mybatis入门之在基于Springboot的框架下拿到MySQL中数据
Mybatis入门之在基于Springboot的框架下拿到MySQL中数据
39 4
|
4月前
|
SQL Java 数据库连接
2万字实操案例之在Springboot框架下基于注解用Mybatis开发实现基础操作MySQL之预编译SQL主键返回增删改查
2万字实操案例之在Springboot框架下基于注解用Mybatis开发实现基础操作MySQL之预编译SQL主键返回增删改查
58 2
|
4月前
|
安全 前端开发 Java
挑战5分钟内基于Springboot+SpringMVC+Mybatis-plus快速构建web后端三层架构
挑战5分钟内基于Springboot+SpringMVC+Mybatis-plus快速构建web后端三层架构
45 1
|
4月前
|
Java 程序员
浅浅纪念花一个月完成Springboot+Mybatis+Springmvc+Vue2+elementUI的前后端交互入门项目
浅浅纪念花一个月完成Springboot+Mybatis+Springmvc+Vue2+elementUI的前后端交互入门项目
45 1
|
4月前
|
缓存 NoSQL Java
在 SSM 架构(Spring + SpringMVC + MyBatis)中,可以通过 Spring 的注解式缓存来实现 Redis 缓存功能
【6月更文挑战第18天】在SSM(Spring+SpringMVC+MyBatis)中集成Redis缓存,涉及以下步骤:添加Spring Boot的`spring-boot-starter-data-redis`依赖;配置Redis连接池(如JedisPoolConfig)和连接工厂;在Service层使用`@Cacheable`注解标记缓存方法,指定缓存名和键生成策略;最后,在主配置类启用缓存注解。通过这些步骤,可以利用Spring的注解实现Redis缓存。
69 2
|
3月前
|
XML 关系型数据库 MySQL
支付系统----微信支付19---集成MyBatis-plus,数据库驱动对应的依赖版本设置问题,5没版本没有cj这个依赖,mysql驱动默认的是版本8,这里是一个父类,数据库都有,写个父类,继承就行
支付系统----微信支付19---集成MyBatis-plus,数据库驱动对应的依赖版本设置问题,5没版本没有cj这个依赖,mysql驱动默认的是版本8,这里是一个父类,数据库都有,写个父类,继承就行
|
3月前
|
关系型数据库 MySQL 数据库
MybatisPlus添加数据数据库没有数据,数据消失,使用Navicate看不到数据,Navicate中Mysql的数据与idea的数据不一定同步,Navicate与idea的数据库同步,其实有分页
MybatisPlus添加数据数据库没有数据,数据消失,使用Navicate看不到数据,Navicate中Mysql的数据与idea的数据不一定同步,Navicate与idea的数据库同步,其实有分页
|
4月前
|
XML Java 数据库连接
MyBatis第二课,灰度发布,@Results注解,使用xml书写mysql
MyBatis第二课,灰度发布,@Results注解,使用xml书写mysql
下一篇
无影云桌面