`
taiwei.peng
  • 浏览: 232450 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

CXF整合Spring发布WebService实例

阅读更多

WebService发布实例实现过程
1.所需jar包
aopalliance.jar
commons-codec-1.6.jar
commons-collections-3.2.1.jar
commons-dbcp-1.4.jar
commons-lang-2.3.jar
commons-logging-1.1.1.jar
commons-pool.jar
cxf-core-3.0.14.jar
cxf-rt-bindings-soap-3.0.14.jar
cxf-rt-databinding-jaxb-3.0.14.jar
cxf-rt-frontend-jaxws-3.0.14.jar
cxf-rt-frontend-simple-3.0.14.jar
cxf-rt-transports-http-3.0.14.jar
cxf-rt-transports-udp-3.0.14.jar
cxf-rt-ws-addr-3.0.14.jar
cxf-rt-wsdl-3.0.14.jar
cxf-rt-ws-policy-3.0.14.jar
log4j-1.2.16.jar
mybatis-3.2.0.jar
mybatis-spring-1.2.1.jar
mysql-connector-java-5.1.7-bin.jar
neethi-3.0.1.jar
spring-aop-4.0.0.RELEASE.jar
spring-aspects-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-jdbc-4.0.0.RELEASE.jar
spring-tx-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
stax2-api-3.1.4.jar
woodstox-core-asl-4.4.1.jar
wsdl4j-1.6.3.jar
xmlschema-core-2.2.2.jar


2.web.xml
<?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/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">

<display-name>DzWebService</display-name>

<!-- 配置监听器,用于初始化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- ServletContext初始化参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/applicationContext.xml
</param-value>
</context-param>

<!-- 字符过滤,防止添加到数据库的数据为乱码 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Servlet初始化参数,配置springmvc模块 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

    <!-- cxf配置 -->
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>


3.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

<!-- 自动扫描包 ,将带有注解的类 纳入spring容器管理 --> 
<context:component-scan base-package="com.soft" />

<!-- 配置数据源属性文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<!-- dbcp 数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc_driver}" />
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
<!-- 初始化连接 -->
<property name="initialSize" value="${jdbc_initialSize}" />
<!-- 最大空闲连接 -->
<property name="maxIdle" value="${jdbc_maxIdle}" />
<!-- 最小空闲连接 -->
<property name="minIdle" value="${jdbc_minIdle}" />
<!-- 最大连接数量 -->
<property name="maxActive" value="${jdbc_maxActive}" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="120" />
<!-- 最长等待时间,单位毫秒 -->
<property name="maxWait" value="3000" />
<property name="validationQuery" value="select 1 from dual" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="3600000" />
<property name="minEvictableIdleTimeMillis" value="18000000" />
<property name="testOnBorrow" value="true" />
</bean>

<!-- mybatis文件配置,扫描所有mapper文件 --> 
<bean id="cfsqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation"
value="classpath:config/mybatis-config.xml" />
</bean>

<!-- spring与mybatis整合配置,扫描所有dao --> 
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.soft.dao" />
<!--
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
-->
<property name="sqlSessionFactoryBeanName" value="cfsqlSessionFactory" />
</bean>

<!-- 事务管理  -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<!-- 启用对事务注解的支持 -->
<tx:annotation-driven transaction-manager="transactionManager" /> 

<!-- ws配置 -->
<import resource="classpath:config/\webService.xml" />

</beans>


4.webService.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://cxf.apache.org/jaxws
    http://cxf.apache.org/schemas/jaxws.xsd ">

<import resource="classpath:META-INF/cxf/cxf.xml" />

<!-- 接口定义 -->
<jaxws:endpoint id="userService" implementor="com.soft.webservice.impl.UserWsImpl" address="/userWS">
</jaxws:endpoint>

</beans>


5.spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

<!-- 扫描controller(controller层注入) --> 
    <context:component-scan base-package="com.soft.controller"/> 

<!-- 开启注解 -->
<mvc:annotation-driven />

    <!--
配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能
-->
<mvc:resources mapping="/img/**" location="/img/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/html/**" location="/html/" />
<mvc:resources mapping="/upload/**" location="/upload/" />

<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- 异常解析器 -->
<bean id="simpleMappingExceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop
key="org.springframework.web.multipart.MaxUploadSizeExceededException">common/fileerror</prop>
</props>
</property>
</bean>

</beans>

6.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<!-- 实体类,简称 -设置别名 -->
<typeAliases>
<typeAlias alias="customer" type="com.soft.model.Customer" />
</typeAliases>

<!-- 实体接口映射资源 -->
<!--
说明:如果xxMapper.xml配置文件放在和xxMapper.java统一目录下,mappers也可以省略,
因为org.mybatis.spring.mapper.MapperFactoryBean默认会去查找与xxMapper.java相同目录和名称的xxMapper.xml
-->
<mappers>
<mapper resource="com/soft/dao/impl/customerMapper.xml" />
</mappers>

</configuration> 

7. 接口
package com.soft.webservice;

import java.util.List;
import javax.jws.WebService;
import com.soft.model.Customer;

@WebService
public interface UserWs {

/**
* 查询用户信息
* @return
*/
public List<Customer> queryUserAll();

}

8.实现类
package com.soft.webservice.impl;

import java.util.List;
import javax.annotation.Resource;
import javax.jws.WebService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.soft.dao.CustomerMapper;
import com.soft.model.Customer;
import com.soft.webservice.UserWs;

@WebService
public class UserWsImpl implements UserWs {

private Log logger = LogFactory.getLog(this.getClass());

@Resource
private CustomerMapper customerMapper;

/**
* 查询用户信息
* @return
*/
@Override
public List<Customer> queryUserAll() {
List<Customer> custList=null;
try{
custList=customerMapper.queryCustomerByParam();
}catch(Exception ce){
logger.error("query user all error",ce);
ce.printStackTrace();
}
return custList;
}

}



 

分享到:
评论

相关推荐

    cxf+spring的webservice实例

    总的来说,"cxf+spring的webservice实例"是一个实践性的教程,旨在帮助开发者理解如何在Spring环境中利用CXF快速构建和部署Web服务。通过这个实例,你可以掌握从创建服务到发布、测试的整个流程,进一步提升你的Java...

    cxf+spring开发webservice实例(java)

    web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。

    简单的webservice+Cxf+Spring数据对接实例以及jar.rar

    简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...

    简单cxf+spring构建webservice服务

    标题“简单cxf+spring构建webservice服务”指的是使用Apache CXF框架与Spring框架结合来创建Web服务。Apache CXF是一个开源的Java框架,它允许开发者创建和消费各种Web服务,包括SOAP和RESTful风格。Spring框架则为...

    cxf+spring开发webservice客户端与服务端实例

    本实例将详细阐述如何利用CXF和Spring来构建Web服务的客户端和服务端。 一、CXF简介 CXF是一个开源的Java框架,专门用于构建和消费Web服务。它支持SOAP、RESTful等多种服务模型,并且可以方便地与Spring框架集成,...

    ssh+cxf整合发布webservice实例

    SSH+CXF整合发布Web服务(Webservice)实例详解 在软件开发中,SSH(Spring、Struts、Hibernate)是一个常见的Java EE应用框架组合,用于构建高效、可维护的企业级应用程序。CXF则是一个开源的Java服务堆栈,主要...

    cxf+spring webService实例

    在这个"CXF+Spring WebService实例"中,我们将深入探讨如何利用这两个工具来创建、发布和消费Web服务。 CXF全称为CXF CXF (CXF XFire + XWS), 是一个开源的Java框架,它支持多种Web服务标准,如SOAP、WSDL、WS-...

    spring整合cxf发布webservice实例

    将下载的demo(包括serviceserverdemo及serviceclientdemo,bat文件在serviceclientdemo的src下)导入eclipse即可运行使用,编译时可能需要修改jdk版本,如果导入有错,可新建web项目,按所下载demo的结构搭建即可,...

    CXF2+Spring2.5开发WebService实例

    Spring还提供了对Web服务的支持,可以通过集成CXF来实现Web服务的发布和消费。 在使用CXF和Spring 2.5开发Web服务时,我们需要进行以下步骤: 1. **环境准备**:确保安装了Java Development Kit (JDK) 1.6或更高...

    webservice cxf 整合spring例子源代码

    【标题】:Webservice CXF 整合Spring的实例源码解析 在Web服务开发中,Apache CXF是一个广泛使用的开源框架,它提供了创建、部署和管理Web服务的强大功能。CXF不仅支持SOAP,还支持RESTful API,使得开发者能够...

    cxf spring maven 实例

    【描述】"cxf spring maven 实例 webservice"强调了这个示例的重点在于创建Web服务。Web服务是一种通过网络进行通信的应用程序,通常基于开放标准如WSDL(Web服务描述语言)和SOAP(简单对象访问协议)。CXF允许...

    cxf结合spring实现webservice

    配置中通常会包含CXF的Bus实例,以及服务的发布地址。 2. **定义服务接口和实现**:编写业务接口,使用JAX-WS的`@WebService`注解标记。然后,创建接口的实现类,这将作为实际的服务提供者。 3. **服务组件注册**...

    cxf+spring webservice demo client

    使用CXF的`JaxWsProxyFactoryBean`,通过Spring配置来实例化服务客户端。设置服务URL和其他必要属性,例如,如果服务使用了WS-Security,可以配置安全策略。 4. **依赖注入**: 在Spring配置文件中,将客户端代理...

    CXF+Spring+Tomcat发布WebService

    【标题】"CXF+Spring+Tomcat发布WebService"涉及的是使用Apache CXF框架与Spring框架结合,在Tomcat服务器上部署和消费Web服务的过程。这是一个常见的企业级应用开发场景,特别是对于实现基于SOAP协议的Web服务。...

    cxf+Spring实现webservice工程

    在CXF和Spring结合的场景下,Spring可以用来管理CXF的服务实例,从而简化服务的生命周期管理。 在"CXF+Spring实现Web服务工程"的实践中,通常会遵循以下步骤: 1. **配置Spring**:创建Spring配置文件,定义服务...

    CXF结合Spring发布Json格式WebService示例

    本实例工程使用Apache CXF组件快速开发WebService。基于Spring框架,使用了Maven项目,但由于时间原因,只使用了Maven Project的框架,还是使用lib文件夹存放所需的cxf库,传入传出对象支持Json格式。

    SSH整合cxf webservice实例

    SSH整合CXF Webservice实例详解 在Java世界中,SSH(Spring、Struts、Hibernate)是一种常见的企业级应用开发框架组合,它提供了强大的MVC(Model-View-Controller)架构支持,以及持久层管理和业务逻辑处理。而CXF...

    springBoot完整整合WebService框架CXF示例

    SpringBoot与CXF整合是构建基于Web服务的应用程序的一个常见实践。CXF是一个开源的Java框架,用于构建和开发服务导向架构(SOA)应用程序,它支持SOAP和RESTful服务。SpringBoot则简化了Spring应用的初始化和配置,...

    Spring整合CXF步骤,Spring实现webService,spring整合WebService

    总的来说,Spring整合CXF的步骤主要包括配置CXF,定义服务接口和实现,然后在Spring中发布这些服务。通过这样的整合,你可以享受到Spring带来的便利,同时利用CXF的强大功能来构建高质量的Web服务。在实际开发中,还...

    CXF2.7+Spring3 Java WebService 集成用例

    - **依赖注入(DI)**:Spring的DI允许CXF组件轻松地接收来自Spring容器的依赖,无需硬编码实例化。 - **配置简化**:通过Spring配置文件,可以集中管理Web服务的生命周期和配置。 - **测试友好**:Spring的单元...

Global site tag (gtag.js) - Google Analytics