---
title: "CXF"
author: "sanshi"
date: "2010-02-03T15:47:58Z"
tags: ["Bean", "Hibernate", "JavaEE", "Servlet", "quartz"]
categories: ["编程语言"]
slug: "cxf"
draft: false
lastmod: "2010-02-03T15:47:58Z"
id: 586806
url: "https://sanshi.iteye.com/blog/586806"
---

CXF服务器端Spring配置文件：

       &lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
 xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
 xmlns:jaxws="[http://cxf.apache.org/jaxws](http://cxf.apache.org/jaxws)"  
 xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans) [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd](http://www.springframework.org/schema/beans/spring-beans-2.5.xsd)  
 [http://cxf.apache.org/jaxws](http://cxf.apache.org/jaxws) [http://cxf.apache.org/schemas/jaxws.xsd](http://cxf.apache.org/schemas/jaxws.xsd)"&gt;

 &lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;  
 &lt;import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /&gt;  
 &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;  
   
   &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  destroy-method="close" &gt;  
  &lt;property name="driverClassName"&gt;  
   &lt;value&gt;oracle.jdbc.driver.OracleDriver&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="url"&gt;  
   &lt;value&gt;jdbc:oracle:thin:@192.168.2.100:1521:orcl&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="username"&gt;  
   &lt;value&gt;sanshi&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="password"&gt;  
   &lt;value&gt;sanshi&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="maxActive"&gt;  
   &lt;value&gt;20&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="maxIdle"&gt;  
   &lt;value&gt;10&lt;/value&gt;  
  &lt;/property&gt;  
  &lt;property name="maxWait"&gt;  
   &lt;value&gt;-1&lt;/value&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
   
   
    
 &lt;bean id="sessionFactory"  
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;  
  &lt;property name="dataSource"&gt;  
   &lt;ref bean="dataSource" /&gt;  
  &lt;/property&gt;  
    
  &lt;property name="mappingLocations"&gt;  
   &lt;list&gt;  
    &lt;value&gt;classpath\*:/com/hongxin/entity/\*.hbm.xml&lt;/value&gt;  
   
   &lt;/list&gt;  
  &lt;/property&gt;  
  &lt;property name="hibernateProperties"&gt;  
   &lt;props&gt;  
    &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.Oracle10gDialect  
 &lt;/prop&gt;  
    &lt;prop key="hibernate.show\_sql"&gt;true&lt;/prop&gt;  
    &lt;prop key="hibernate.format\_sql"&gt;true&lt;/prop&gt;  
      
    &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;  
      
    &lt;prop key="hibernate.jdbc.fetch\_size"&gt;50&lt;/prop&gt;  
   &lt;/props&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
   
 &lt;bean id="transactionManager"  
  class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;  
  &lt;property name="sessionFactory"&gt;  
   &lt;ref local="sessionFactory" /&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
  &lt;bean id="txProxyTemplate" abstract="true" lazy-init="true"  
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;  
  &lt;property name="transactionManager"&gt;  
   &lt;ref bean="transactionManager" /&gt;  
  &lt;/property&gt;  
  &lt;property name="transactionAttributes"&gt;  
   &lt;props&gt;  
    &lt;prop key="save\*"&gt;PROPAGATION\_REQUIRED&lt;/prop&gt;  
    &lt;prop key="remove\*"&gt;PROPAGATION\_REQUIRED&lt;/prop&gt;  
    &lt;prop key="delete\*"&gt;PROPAGATION\_REQUIRED&lt;/prop&gt;  
    &lt;prop key="\*"&gt;PROPAGATION\_REQUIRED&lt;/prop&gt;  
   &lt;/props&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
   
     &lt;bean id="userAccountDaoInterface" class="com.hongxin.userAccount.UserAccountDaoInterfaceImpl"&gt;  
     &lt;property name="sessionFactory"&gt;  
       &lt;ref bean="sessionFactory"/&gt;  
      &lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="accountDaoInterface" class="com.hongxin.account.AccountDaoInterfaceImpl" autowire="byName"&gt;  
      &lt;property name="sessionFactory"&gt;  
       &lt;ref bean="sessionFactory"/&gt;  
      &lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="sendMessageDaoInterface" class="com.hongxin.sendMessage.SendMessageDaoInterfaceImpl"&gt;  
      &lt;property name="sessionFactory"&gt;  
       &lt;ref bean="sessionFactory"/&gt;  
      &lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="sxtClient" class="com.hongxin.sendMessage.SXTClient" autowire="byName"&gt;  
     &lt;property name="accountDaoInterface"&gt;  
      &lt;ref bean="accountDaoInterface"/&gt;  
     &lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="receiveMessageDaoInterface" class="com.hongxin.receiveMessage.ReceiveMessageDaoInterfaceImpl"&gt;  
      &lt;property name="sessionFactory"&gt;  
       &lt;ref bean="sessionFactory"/&gt;  
      &lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="sendMessageInterface" class="com.hongxin.sendMessage.SendMessageInterfaceImpl" autowire="byName"&gt;  
    &lt;/bean&gt;  
    &lt;bean id="receiveShortMessageService" class="com.hongxin.receiveMessageQuartzJob.ReceiveShortMessageServiceImpl" autowire="byName"/&gt;  
    &lt;bean id="quartzJob" class="com.hongxin.receiveMessageQuartzJob.ReceiveShortMessageQuartzJob" autowire="byName"/&gt;  
    
    &lt;jaxws:endpoint id="accountService"  
  implementor="#accountDaoInterface" address="/accountServices"&gt;  
 &lt;/jaxws:endpoint&gt;  
    &lt;jaxws:endpoint id="receiveMessage"  
  implementor="#receiveMessageDaoInterface" address="/receiveMessage"&gt;  
 &lt;/jaxws:endpoint&gt;  
 &lt;jaxws:endpoint id="querySendMessage"  
  implementor="#sendMessageDaoInterface" address="/querySendMessage"&gt;  
 &lt;/jaxws:endpoint&gt;  
 &lt;jaxws:endpoint id="sendMessage"  
  implementor="#sendMessageInterface" address="/sendMessage"&gt;  
 &lt;/jaxws:endpoint&gt;  
 &lt;jaxws:endpoint id="userAccount"  
     implementor="#userAccountDaoInterface" address="/userAccount"&gt;  
 &lt;/jaxws:endpoint&gt;  
    &lt;bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;  
      &lt;!-- 调用的类 --&gt;             
       &lt;property name="targetObject"&gt;  
           &lt;ref bean="quartzJob"/&gt;  
        &lt;/property&gt;              
      &lt;!-- 调用类中的方法 --&gt;   
      &lt;property name="targetMethod"&gt;  
      &lt;value&gt;executeJob&lt;/value&gt;  
      &lt;/property&gt;  
    &lt;/bean&gt;   
    &lt;!-- 定义触发时间 --&gt;  
    &lt;bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;  
    &lt;property name="jobDetail"&gt;  
    &lt;ref bean="jobtask"/&gt;  
    &lt;/property&gt;  
     &lt;!-- cron表达式 --&gt;  
     &lt;property name="cronExpression"&gt;  
       &lt;value&gt;0 \*/4 * * * ?&lt;/value&gt;  
    &lt;/property&gt;  
    &lt;/bean&gt;     
     &lt;!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序  --&gt;  
     &lt;bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;  
       &lt;property name="triggers"&gt;  
          &lt;list&gt;  
            &lt;ref bean="doTime"/&gt;  
          &lt;/list&gt;  
       &lt;/property&gt;  
     &lt;/bean&gt;    
&lt;/beans&gt;

 

web.xml配置文件：

   &lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;web-app version="2.5"  
 xmlns="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)"  
 xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
 xsi:schemaLocation="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)  
 [http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd)"&gt;  
 &lt;context-param&gt;  
  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;  
  &lt;param-value&gt;  
   classpath:applicationContext.xml     
  &lt;/param-value&gt;  
 &lt;/context-param&gt;  
 &lt;servlet&gt;  
  &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;  
  &lt;servlet-class&gt;  
   org.apache.cxf.transport.servlet.CXFServlet  
  &lt;/servlet-class&gt;  
  &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;  
 &lt;/servlet&gt;  
 &lt;servlet-mapping&gt;  
  &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;  
  &lt;url-pattern&gt;/services/\*&lt;/url-pattern&gt;  
 &lt;/servlet-mapping&gt;  
 &lt;listener&gt;  
  &lt;listener-class&gt;  
   org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;  
 &lt;/listener&gt;  
  &lt;welcome-file-list&gt;  
    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;  
  &lt;/welcome-file-list&gt;  
&lt;/web-app&gt;  
在接口上注明@WebService

在实现类上注明：@WebService(endpointInterface = "com.hongxin.receiveMessage.ReceiveMessageDaoInterface")括号里是要实现的接口