Spring+SpringMVC+Mybatis框架集成Apache CXF2.7集成 mongodb集成quartz

项目结构:


1、ssm框架基础jar 包

[html]  view plain  copy
  1. aopalliance.jar  
  2. aspectjrt.jar  
  3. aspectjweaver.jar  
  4. commons-beanutils-1.9.2.jar  
  5. commons-codec-1.9.jar  
  6. commons-collections-3.2.1.jar  
  7. commons-dbcp-1.4.jar  
  8. commons-fileupload-1.3.1.jar  
  9. commons-io-2.4.jar  
  10. commons-lang-2.6.jar  
  11. commons-logging-1.2.jar  
  12. commons-net-3.1.jar  
  13. commons-pool-1.6.jar  
  14. commons-pool2-2.2.jar  
  15. druid-1.0.9.jar  
  16. fastjson-1.1.39.jar  
  17. freemarker-2.3.19.jar  
  18. hamcrest-core-1.3.jar  
  19. jackson-all-1.9.5.jar  
  20. jboss-logging-3.1.0.CR2.jar  
  21. jettison-1.0.1.jar  
  22. jstl-1.1.2.jar  
  23. junit-4.11.jar  
  24. log4j-1.2.17.jar  
  25. log4j-over-slf4j-1.7.7.jar  
  26. mybatis-3.2.6.jar  
  27. mybatis-spring-1.2.2.jar  
  28. mysql-connector-java-5.1.30-bin.jar  
  29. servlet-api.jar  
  30. slf4j-api-1.7.7.jar  
  31. slf4j-ext-1.7.7.jar  
  32. spring-aop-4.0.2.RELEASE.jar  
  33. spring-aspects-4.0.2.RELEASE.jar  
  34. spring-beans-4.0.2.RELEASE.jar  
  35. spring-context-4.0.2.RELEASE.jar  
  36. spring-context-support-4.0.2.RELEASE.jar  
  37. spring-core-4.0.2.RELEASE.jar  
  38. spring-expression-4.0.2.RELEASE.jar  
  39. spring-jdbc-4.0.2.RELEASE.jar  
  40. spring-oxm-4.0.2.RELEASE.jar  
  41. spring-test-4.0.2.RELEASE.jar  
  42. spring-tx-4.0.2.RELEASE.jar  
  43. spring-web-4.0.4.RELEASE.jar  
  44. spring-webmvc-4.0.2.RELEASE.jar  
  45. standard-1.1.2.jar  
2.Apache CXF2.7 关联jar文件

[html]  view plain  copy
  1. cxf-2.7.3.jar  
  2. httpasyncclient-4.0-beta3.jar  
  3. httpclient-4.2.1.jar  
  4. httpcore-4.2.2.jar  
  5. httpcore-nio-4.2.2.jar  
  6. neethi-3.0.2.jar  
  7. wsdl4j-1.6.2.jar  
  8. xmlschema-core-2.0.3.jar  

3、SpringMVC的配置文件在网上存在很多资源,这里不做解释,直接上传我的web.xml 文件

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.5"   
  3.     xmlns="http://java.sun.com/xml/ns/javaee"   
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
  6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  7.   <display-name></display-name>   
  8.     
  9.   <context-param>  
  10.         <param-name>contextConfigLocation</param-name>  
  11.         <param-value>classpath:spring/spring-context.xml</param-value>  
  12.     </context-param>  
  13.    
  14.     <filter>  
  15.         <filter-name>encodingFilter</filter-name>  
  16.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  17.         <init-param>  
  18.             <param-name>encoding</param-name>  
  19.             <param-value>UTF-8</param-value>  
  20.         </init-param>  
  21.         <init-param>  
  22.             <param-name>forceEncoding</param-name>  
  23.             <param-value>true</param-value>  
  24.         </init-param>  
  25.     </filter>  
  26.     <filter-mapping>  
  27.         <filter-name>encodingFilter</filter-name>  
  28.         <url-pattern>/*</url-pattern>  
  29.     </filter-mapping>  
  30.    
  31.     <listener>  
  32.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  33.     </listener>  
  34.    
  35.     <servlet>  
  36.         <servlet-name>springMVC</servlet-name>  
  37.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  38.         <init-param>  
  39.             <param-name>contextConfigLocation</param-name>  
  40.             <param-value>classpath:spring-mvc.xml</param-value>  
  41.         </init-param>  
  42.         <load-on-startup>1</load-on-startup>  
  43.     </servlet>  
  44.     <servlet-mapping>  
  45.         <servlet-name>springMVC</servlet-name>  
  46.         <url-pattern>/</url-pattern>  
  47.     </servlet-mapping>  
  48.     <!--配置apche cxf Servlet  -->  
  49.   <!-- 配置cxf的核心控制器 -->        
  50.     <servlet>   
  51.         <servlet-name>CXFServlet</servlet-name>   
  52.         <servlet-class>   
  53.             org.apache.cxf.transport.servlet.CXFServlet    
  54.         </servlet-class>   
  55.         <load-on-startup>2</load-on-startup>   
  56.     </servlet>   
  57.    
  58.    <!-- 所有来自/webservice/*的请求交给cxf处理 -->   
  59.     <servlet-mapping>   
  60.         <servlet-name>CXFServlet</servlet-name>   
  61.         <url-pattern>/webservice/*</url-pattern>      
  62.     </servlet-mapping>  
  63.     
  64.   
  65. </web-app>  

4、spring-context.xml 配置文件

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.     xmlns:tx="http://www.springframework.org/schema/tx"  
  7.     xmlns:aop="http://www.springframework.org/schema/aop"  
  8.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  9.                         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
  10.                         http://www.springframework.org/schema/context    
  11.                         http://www.springframework.org/schema/context/spring-context-3.1.xsd    
  12.                         http://www.springframework.org/schema/tx  
  13.                         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
  14.                         http://www.springframework.org/schema/mvc    
  15.                         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd  
  16.                         http://www.springframework.org/schema/aop   
  17.                         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">     
  18.     <!-- 引入配置文件 -->  
  19.     <bean id="propertyConfigurer"  
  20.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  21.         <property name="locations">  
  22.             <list>    
  23.                 <value>classpath:jdbc.properties</value>    
  24.                 <value>classpath:memcached.properties</value>    
  25.             </list>   
  26.         </property>  
  27.     </bean>  
  28.   
  29.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  30.         destroy-method="close">  
  31.         <property name="driverClassName" value="${driver}" />  
  32.         <property name="url" value="${url}" />  
  33.         <property name="username" value="${username}" />  
  34.         <property name="password" value="${password}" />  
  35.         <!-- 初始化连接大小 -->  
  36.         <property name="initialSize" value="${initialSize}"></property>  
  37.         <!-- 连接池最大数量 -->  
  38.         <property name="maxActive" value="${maxActive}"></property>  
  39.         <!-- 连接池最大空闲 -->  
  40.         <property name="maxIdle" value="${maxIdle}"></property>  
  41.         <!-- 连接池最小空闲 -->  
  42.         <property name="minIdle" value="${minIdle}"></property>  
  43.         <!-- 获取连接最大等待时间 -->  
  44.         <property name="maxWait" value="${maxWait}"></property>  
  45.     </bean>  
  46.   
  47.     <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
  48.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  49.         <property name="dataSource" ref="dataSource" />  
  50.         <!-- 自动扫描mapping.xml文件 -->  
  51.         <property name="mapperLocations" value="classpath:com/wlsq/oauth/mapper/*.xml"></property>  
  52.     </bean>  
  53.   
  54.     <!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
  55.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  56.         <property name="basePackage" value="com.wlsq.oauth.dao" />  
  57.         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
  58.     </bean>  
  59.   
  60.     <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->  
  61.     <bean id="transactionManager"  
  62.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  63.         <property name="dataSource" ref="dataSource" />  
  64.     </bean>  
  65.       
  66.      <!-- 通知 -->  
  67.     <tx:advice id="tx"  
  68.         transaction-manager="transactionManager">  
  69.         <tx:attributes>  
  70.             <tx:method name="delete*" propagation="REQUIRED" />  
  71.             <tx:method name="insert*" propagation="REQUIRED" />  
  72.             <tx:method name="update*" propagation="REQUIRED" />  
  73.             <tx:method name="find*" read-only="true" />  
  74.             <tx:method name="get*" read-only="true" />  
  75.             <tx:method name="select*" read-only="true" />  
  76.         </tx:attributes>  
  77.     </tx:advice>  
  78.   
  79.     <aop:config>  
  80.         <aop:pointcut id="pc" expression="execution(* com.common.service.*.*(..))" />  
  81.         <!--把事务控制在Service层-->  
  82.         <aop:advisor pointcut-ref="pc" advice-ref="tx" />  
  83.     </aop:config>  
  84.       
  85.     <!--spring 集成缓存服务器(memcached) -->  
  86.      <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"  
  87.         factory-method="getInstance" init-method="initialize"  
  88.         destroy-method="shutDown">  
  89.   
  90.         <constructor-arg>  
  91.             <value>memCachedPool</value>  
  92.         </constructor-arg>  
  93.           
  94.         <property name="servers">  
  95.             <list>  
  96.                 <value>${memcache.server}</value>  
  97.             </list>  
  98.         </property>  
  99.           
  100.         <property name="initConn">  
  101.             <value>${memcache.initConn}</value>  
  102.         </property>  
  103.           
  104.         <property name="minConn">  
  105.             <value>${memcache.minConn}</value>  
  106.         </property>  
  107.   
  108.         <property name="maxConn">  
  109.             <value>${memcache.maxConn}</value>  
  110.         </property>  
  111.   
  112.         <property name="maintSleep">  
  113.             <value>${memcache.maintSleep}</value>  
  114.         </property>  
  115.   
  116.         <property name="nagle">  
  117.             <value>${memcache.nagle}</value>  
  118.         </property>  
  119.   
  120.         <property name="socketTO">  
  121.             <value>${memcache.socketTO}</value>  
  122.         </property>  
  123.     </bean>  
  124.   
  125.     <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">  
  126.         <constructor-arg>  
  127.             <value>memCachedPool</value>  
  128.         </constructor-arg>  
  129.     </bean>  
  130.       
  131.     <!--ssm 集成 mongodb  -->  
  132.     <import resource="classpath:spring/spring-mongodb.xml"/>  
  133.     <!--ssm 集成quartz(定时任务框架)  -->  
  134.     <import resource="classpath:spring/spring-quartz.xml"/>  
  135.     <!--ssm 集成 apache cxf(webservice)  -->  
  136.     <import resource="classpath:spring/apache-cxf.xml"/>  
  137.   
  138. </beans>  

5、apache-cxf .xml 配置文件

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  7.  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  8.  http://www.springframework.org/schema/tx  
  9.  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
  10.  http://www.springframework.org/schema/aop  
  11.  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  12.  http://www.springframework.org/schema/context  
  13.  http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  14.  http://cxf.apache.org/jaxws  
  15.  http://cxf.apache.org/schemas/jaxws.xsd">  
  16.   
  17.     <!--CXF配置 -->  
  18.     <import resource="classpath:META-INF/cxf/cxf.xml" />  
  19.     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
  20.     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
  21.   
  22.     <!--服务端发布的webservice   
  23.         在spring中使用jaxws:endpoint元素来暴露Web Service   
  24.         id:指在spring配置的bean的ID   
  25.         Implementor:指明具体的实现类  
  26.         Address:指明这个web service的相对地址 -->  
  27.     <jaxws:endpoint id="helloWorld" implementor="com.wlsq.oauth.webservice.impl.HelloWorldImpl"  
  28.         address="/HelloWorld" />  
  29. </beans>  

6、webservice 接口开发和接口实现类

[html]  view plain  copy
  1. package com.wlsq.oauth.webservice;  
  2.   
  3. import javax.jws.WebMethod;  
  4. import javax.jws.WebParam;  
  5. import javax.jws.WebService;  
  6.   
  7. @WebService  
  8. public interface HelloWorld {  
  9.     @WebMethod  
  10.     String sayHello(@WebParam(name="username") String username);  
  11. }  
[html]  view plain  copy
  1. package com.wlsq.oauth.webservice.impl;  
  2.   
  3. import javax.jws.WebService;  
  4.   
  5. import com.wlsq.oauth.webservice.HelloWorld;  
  6.   
  7.   
  8. @WebService(endpointInterface="com.wlsq.oauth.webservice.HelloWorld",serviceName="helloWorld",targetNamespace="http://dao.cxf.ws.com/")  
  9. public class HelloWorldImpl implements HelloWorld{  
  10.   
  11.     public String sayHello(String username) {  
  12.         System.out.println("sayHello() is called");  
  13.         return username +" helloWorld";  
  14.     }  
  15. }  

分享该项目资源下载路径: http://download.csdn.net/download/zhouzhiwengang/9526511
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值