maven+ssm+cxf3配置例子

以下只是简单记录 ssm结合cxf3的配置

提供方配置:::

pom.xml

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3     <modelVersion>4.0.0</modelVersion>
  4     <groupId>com.test.soaservice</groupId>
  5     <artifactId>soaservice</artifactId>
  6     <packaging>war</packaging>
  7     <version>0.0.1</version>
  8     <name>soaservice Maven Webapp</name>
  9     <url>http://maven.apache.org</url>
 10     <properties>
 11         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 12         <!-- spring版本号 -->
 13         <spring.version>4.2.0.RELEASE</spring.version>
 14         <!-- mybatis版本号 -->
 15         <mybatis.version>3.4.1</mybatis.version>
 16         <!-- log4j日志文件管理包版本 -->
 17         <slf4j.version>1.7.7</slf4j.version>
 18         <log4j.version>1.2.17</log4j.version>
 19         <cxf.version>3.1.9</cxf.version>
 20     </properties>
 21     <dependencies>
 22         <dependency>
 23             <groupId>junit</groupId>
 24             <artifactId>junit</artifactId>
 25             <version>3.8.1</version>
 26             <scope>test</scope>
 27         </dependency>
 28 
 29         <!-- springframework包 -->
 30 
 31 
 32         <!-- SpringMVC 应用 spring-webmvc spring-context -->
 33         <dependency>
 34             <groupId>org.springframework</groupId>
 35             <artifactId>spring-context</artifactId>
 36             <version>${spring.version}</version>
 37         </dependency>
 38         <dependency>
 39             <groupId>org.springframework</groupId>
 40             <artifactId>spring-core</artifactId>
 41             <version>${spring.version}</version>
 42         </dependency>
 43         <dependency>
 44             <groupId>org.springframework</groupId>
 45             <artifactId>spring-aspects</artifactId>
 46             <version>${spring.version}</version>
 47         </dependency>
 48         <dependency>
 49             <groupId>org.springframework</groupId>
 50             <artifactId>spring-expression</artifactId>
 51             <version>${spring.version}</version>
 52         </dependency>
 53         <dependency>
 54             <groupId>org.springframework</groupId>
 55             <artifactId>spring-beans</artifactId>
 56             <version>${spring.version}</version>
 57         </dependency>
 58 
 59         <dependency>
 60             <groupId>org.springframework</groupId>
 61             <artifactId>spring-tx</artifactId>
 62             <version>${spring.version}</version>
 63         </dependency>
 64 
 65         <dependency>
 66             <groupId>org.springframework</groupId>
 67             <artifactId>spring-jdbc</artifactId>
 68             <version>${spring.version}</version>
 69         </dependency>
 70         <dependency>
 71             <groupId>org.springframework</groupId>
 72             <artifactId>spring-aop</artifactId>
 73             <version>${spring.version}</version>
 74         </dependency>
 75         <dependency>
 76             <groupId>org.springframework</groupId>
 77             <artifactId>spring-test</artifactId>
 78             <version>${spring.version}</version>
 79         </dependency>
 80         <dependency>
 81             <groupId>org.springframework</groupId>
 82             <artifactId>spring-web</artifactId>
 83             <version>${spring.version}</version>
 84         </dependency>
 85         <dependency>
 86             <groupId>org.springframework</groupId>
 87             <artifactId>spring-webmvc</artifactId>
 88             <version>${spring.version}</version>
 89         </dependency>
 90         <!-- mybatis核心包 -->
 91         <dependency>
 92             <groupId>org.mybatis</groupId>
 93             <artifactId>mybatis</artifactId>
 94             <version>${mybatis.version}</version>
 95         </dependency>
 96         <!-- mybatis/spring包 -->
 97         <dependency>
 98             <groupId>org.mybatis</groupId>
 99             <artifactId>mybatis-spring</artifactId>
100             <version>1.3.0</version>
101         </dependency>
102         <!-- mybatis/mybatis-plus -->
103         <dependency>
104             <groupId>com.baomidou</groupId>
105             <artifactId>mybatis-plus</artifactId>
106             <version>1.5</version>
107         </dependency>
108         <dependency>
109             <groupId>mysql</groupId>
110             <artifactId>mysql-connector-java</artifactId>
111             <version>5.1.39</version>
112         </dependency>
113         <!-- JSTL标签类 -->
114         <dependency>
115             <groupId>jstl</groupId>
116             <artifactId>jstl</artifactId>
117             <version>1.2</version>
118         </dependency>
119         <!-- 日志文件管理包 -->
120         <!-- log start -->
121         <dependency>
122             <groupId>log4j</groupId>
123             <artifactId>log4j</artifactId>
124             <version>${log4j.version}</version>
125         </dependency>
126         <!-- 格式化对象,方便输出日志 -->
127         <dependency>
128             <groupId>com.alibaba</groupId>
129             <artifactId>fastjson</artifactId>
130             <version>1.2.16</version>
131         </dependency>
132 
133 
134         <dependency>
135             <groupId>org.slf4j</groupId>
136             <artifactId>slf4j-api</artifactId>
137             <version>${slf4j.version}</version>
138         </dependency>
139 
140         <dependency>
141             <groupId>org.slf4j</groupId>
142             <artifactId>slf4j-log4j12</artifactId>
143             <version>${slf4j.version}</version>
144         </dependency>
145 
146         <dependency>
147             <groupId>javax.servlet</groupId>
148             <artifactId>servlet-api</artifactId>
149             <version>2.5</version>
150         </dependency>
151         <!-- 配置数据源,使用的是alibaba的Druid(德鲁伊)数据源 -->
152         <dependency>
153             <groupId>com.alibaba</groupId>
154             <artifactId>druid</artifactId>
155             <version>1.0.27</version>
156         </dependency>
157 
158         <dependency>
159             <groupId>org.ow2.asm</groupId>
160             <artifactId>asm</artifactId>
161             <version>5.1</version>
162         </dependency>
163         <dependency>
164             <groupId>cglib</groupId>
165             <artifactId>cglib</artifactId>
166             <version>3.2.4</version>
167         </dependency>
168         <dependency>
169             <groupId>org.aopalliance</groupId>
170             <artifactId>com.springsource.org.aopalliance</artifactId>
171             <version>1.0.0</version>
172             <classifier>sources</classifier>
173         </dependency>
174         <dependency>
175             <groupId>org.apache.commons</groupId>
176             <artifactId>com.springsource.org.apache.commons.logging</artifactId>
177             <version>1.1.1</version>
178         </dependency>
179         <dependency>
180             <groupId>org.aspectj</groupId>
181             <artifactId>com.springsource.org.aspectj.weaver</artifactId>
182             <version>1.6.8.RELEASE</version>
183         </dependency>
184         <dependency>
185             <groupId>net.sf.ehcache</groupId>
186             <artifactId>ehcache</artifactId>
187             <version>2.10.3</version>
188         </dependency>
189         <dependency>
190             <groupId>org.mybatis.caches</groupId>
191             <artifactId>mybatis-ehcache</artifactId>
192             <version>1.1.0</version>
193         </dependency>
194         
195         <!-- cxf的jar包 -->
196         <dependency>
197             <groupId>org.apache.cxf</groupId>
198             <artifactId>cxf-rt-frontend-jaxws</artifactId>
199             <version>${cxf.version}</version>
200         </dependency>
201         <dependency>
202             <groupId>org.apache.cxf</groupId>
203             <artifactId>cxf-rt-transports-http</artifactId>
204             <version>${cxf.version}</version>
205         </dependency>
206 
207     </dependencies>
208 
209     <build>
210         <finalName>soaservice</finalName>
211         <resources>
212             <resource>
213                 <directory>src/main/java</directory>
214                 <includes>
215                     <include>**/*.xml</include>
216                 </includes>
217                 <filtering>false</filtering>
218             </resource>
219             <resource>
220                 <directory>src/main/resources</directory>
221                 <includes>
222                     <include>**/*.xml</include>
223                     <include>**/*.properties</include>
224                 </includes>
225                 <filtering>false</filtering>
226             </resource>
227         </resources>
228     </build>
229 </project>

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 4     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5     id="WebApp_ID" version="3.1">
 6 
 7     <context-param>
 8         <param-name>contextConfigLocation</param-name>
 9         <param-value>classpath:spring-mybatis.xml,classpath:spring-cxf-config.xml</param-value>
10     </context-param>
11     <listener>
12         <description>spring监听器</description>
13         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
14     </listener>
15     <filter>
16         <filter-name>characterEncodingFilter</filter-name>
17         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
18         <init-param>
19             <param-name>encoding</param-name>
20             <param-value>UTF-8</param-value>
21         </init-param>
22         <init-param>
23             <param-name>forceEncoding</param-name>
24             <param-value>true</param-value>
25         </init-param>
26     </filter>
27     <!-- CXF配置 -->
28     <servlet>
29         <description>CXF Endpoint</description>
30         <display-name>cxf</display-name>
31         <servlet-name>cxf</servlet-name>
32         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
33         <load-on-startup>2</load-on-startup>
34     </servlet>
35     <servlet-mapping>
36         <servlet-name>cxf</servlet-name>
37         <url-pattern>/webservice/*</url-pattern>
38     </servlet-mapping>
39     <display-name>Archetype Created Web Application</display-name>
40 </web-app>

spring-cxf-config.xml

 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"    
 4     xmlns:jaxws="http://cxf.apache.org/jaxws"    
 5     xsi:schemaLocation=" http://www.springframework.org/schema/beans    
 6     http://www.springframework.org/schema/beans/spring-beans.xsd    
 7     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">   
 8     
 9  <jaxws:endpoint id="iTestService" implementor="com.soa.service.impl.TestServiceImpl"
10   address="/testServiceImpl"/>
11 </beans>

spring-mybatis.xml

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <beans
  3     xmlns="http://www.springframework.org/schema/beans"
  4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5     xmlns:p="http://www.springframework.org/schema/p"
  6     xmlns:context="http://www.springframework.org/schema/context"
  7     xmlns:aop="http://www.springframework.org/schema/aop"
  8     xmlns:tx="http://www.springframework.org/schema/tx"  
  9     xsi:schemaLocation="
 10     http://www.springframework.org/schema/tx
 11     http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
 12     http://www.springframework.org/schema/aop   
 13     http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
 14     http://www.springframework.org/schema/context  
 15     http://www.springframework.org/schema/context/spring-context-4.2.xsd  
 16     http://www.springframework.org/schema/beans 
 17     http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
 18     
 19         <context:annotation-config />
 20     <!-- 自动扫描(service),(dao) -->
 21     <context:component-scan base-package="com.soa.mapper,com.soa.service">
 22         <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
 23         <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
 24     </context:component-scan>
 25     
 26     <!-- properties配置文件 -->  
 27     <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 28          <!-- 是否忽略不可解析的 -->  
 29         <property name="ignoreUnresolvablePlaceholders" value="true" />
 30          <property name="locations">  
 31             <list>  
 32                 <value>classpath:jdbc.properties</value>  
 33             </list>  
 34         </property>  
 35     </bean>
 36 
 37     
 38     <!-- ========================================配置数据源========================================= -->
 39     <!-- 配置数据源,使用的是alibaba的Druid(德鲁伊)数据源 -->
 40     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
 41         <property name="url" value="${url}" />
 42         <property name="username" value="${username}" />
 43         <property name="password" value="${password}" />
 44         <!-- 初始化连接大小 -->
 45         <property name="initialSize" value="0" />
 46         <!-- 连接池最大使用连接数量 -->
 47         <property name="maxActive" value="20" />
 48         <!-- 连接池最大空闲 -->
 49         <property name="maxIdle" value="20" />
 50         <!-- 连接池最小空闲 -->
 51         <property name="minIdle" value="0" />
 52         <!-- 获取连接最大等待时间 -->
 53         <property name="maxWait" value="60000" />
 54         <property name="validationQuery" value="${validationQuery}" />
 55         <property name="testOnBorrow" value="false" />
 56         <property name="testOnReturn" value="false" />
 57         <property name="testWhileIdle" value="true" />
 58         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
 59         <property name="timeBetweenEvictionRunsMillis" value="60000" />
 60         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
 61         <property name="minEvictableIdleTimeMillis" value="25200000" />
 62         <!-- 打开removeAbandoned功能 -->
 63         <property name="removeAbandoned" value="true" />
 64         <!-- 1800秒,也就是30分钟 -->
 65         <property name="removeAbandonedTimeout" value="1800" />
 66         <!-- 关闭abanded连接时输出错误日志 -->
 67         <property name="logAbandoned" value="true" />
 68         <!-- 监控数据库 -->
 69         <!-- <property name="filters" value="stat" /> -->
 70         <property name="filters" value="mergeStat" />
 71     </bean>
 72     
 73     <!-- ========================================针对myBatis的配置项============================== -->
 74     <!-- 配置sqlSessionFactory -->
 75     <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
 76         <!-- 实例化sqlSessionFactory时需要使用上述配置好的数据源以及SQL映射文件 -->
 77          <property name="typeAliasesPackage" value="com.soa.entity" />
 78          
 79         <property name="dataSource" ref="dataSource" />
 80            <!-- 自动扫描Mybatis的Mapper.xml文件 -->
 81            <property name="mapperLocations" value="classpath:com/soa/mapper/xml/*Mapper.xml" />
 82         <!-- <property name="mapperLocations" value="classpath:com/zk/mapping/*.xml" /> -->
 83           <!-- 插件配置项  -->
 84     <property name="plugins">
 85         <array>
 86             <!-- 分页插件配置 -->
 87             <bean id="paginationInterceptor" class="com.baomidou.mybatisplus.plugins.PaginationInterceptor">
 88                 <property name="dialectType" value="mysql" />
 89             </bean>
 90         </array>
 91     </property>
 92     </bean>
 93     
 94     <!-- 配置扫描器 -->
 95     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
 96         <!-- 扫描com.xxx.dao这个包以及它的子包下的所有映射接口类 -->
 97         <property name="basePackage" value="com.soa.mapper" />
 98         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
 99     </bean>
100     
101     <!-- 配置事务管理器 -->
102     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
103         <property name="dataSource" ref="dataSource" />
104     </bean>
105     
106     <!-- 拦截器方式配置事物 -->
107     <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
108         <tx:attributes>
109             <tx:method name="add*" propagation="REQUIRED" />
110             <tx:method name="append*" propagation="REQUIRED" />
111             <tx:method name="insert*" propagation="REQUIRED" />
112             <tx:method name="save*" propagation="REQUIRED" />
113             <tx:method name="update*" propagation="REQUIRED" />
114             <tx:method name="modify*" propagation="REQUIRED" />
115             <tx:method name="edit*" propagation="REQUIRED" />
116             <tx:method name="delete*" propagation="REQUIRED" />
117             <tx:method name="remove*" propagation="REQUIRED" />
118             <tx:method name="repair" propagation="REQUIRED" />
119             <tx:method name="delAndRepair" propagation="REQUIRED" />
120             <tx:method name="get*" propagation="SUPPORTS" />
121             <tx:method name="find*" propagation="SUPPORTS" />
122             <tx:method name="load*" propagation="SUPPORTS" />
123             <tx:method name="search*" propagation="SUPPORTS" />
124             <tx:method name="datagrid*" propagation="SUPPORTS" />
125             <tx:method name="*" propagation="SUPPORTS" />
126         </tx:attributes>
127     </tx:advice>
128     <aop:config>
129         <aop:pointcut id="transactionPointcut" expression="execution(* com.soa.service..*Impl.*(..))" />
130         <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
131     </aop:config>
132     <!-- 配置druid监控spring jdbc -->
133     <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"></bean>
134     <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
135         <property name="patterns">
136             <list>
137                 <value>com.soa.service.*</value>
138             </list>
139         </property>
140     </bean>
141     <aop:config>
142         <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
143     </aop:config>
144     
145     </beans>

 

ITestService.java 接口

 1 package com.soa.service;
 2 import java.util.List;
 3 import javax.jws.WebService;
 4 import javax.jws.soap.SOAPBinding;
 5 import javax.jws.soap.SOAPBinding.Style;
 6 import com.soa.entity.Test;
 7 /**
 8  *
 9  * Test 表数据服务层接口
10  *extends ISuperService<Test>
11  */
12 @WebService
13 @SOAPBinding(style = Style.RPC)
14 public interface ITestService  {
15      List<Test> selectAll();
16 }

TestServiceImpl.java 接口实现

 1 package com.soa.service.impl;
 2 import java.util.List;
 3 import javax.jws.WebService;
 4 import javax.jws.soap.SOAPBinding;
 5 import javax.jws.soap.SOAPBinding.Style;
 6 import org.springframework.beans.factory.annotation.Autowired;
 7 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 8 import com.soa.entity.Test;
 9 import com.soa.mapper.TestMapper;
10 import com.soa.service.ITestService;
11 
12 /**
13  *
14  * Test 表数据服务层接口实现类
15  *
16  */
17 @SOAPBinding(style = Style.RPC)
18 @SuppressWarnings("deprecation")
19 @WebService(endpointInterface="com.soa.service.ITestService")//endpointInterface是为了在实现多个接口情况下指明webservice的接口  
20 public class TestServiceImpl  implements ITestService {
21    @Autowired
22    private TestMapper testMapper;
23     public List<Test> selectAll() {
24         //使用mybatis-plus查询全部
25         return testMapper.selectList(new EntityWrapper<Test>(null));
26     }
27 }

当提供方服务配置完成后发布运行:

Available SOAP services:http://127.0.0.1:8080/soaservice/webservice

ITestService
  • selectAll
Endpoint address: http://127.0.0.1:8080/soaservice/webservice/testServiceImpl
WSDL : {http://impl.service.soa.com/}TestServiceImplService
Target namespace: http://impl.service.soa.com/

 

以下配置消费方::::::

pom.xml

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3   <modelVersion>4.0.0</modelVersion>
  4   <groupId>com.test.soaclient</groupId>
  5   <artifactId>soaclient</artifactId>
  6   <packaging>war</packaging>
  7   <version>0.0.1</version>
  8   <name>soaclient Maven Webapp</name>
  9   <url>http://maven.apache.org</url>
 10   <properties>
 11         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 12         <!-- spring版本号 -->
 13         <spring.version>4.2.0.RELEASE</spring.version>
 14         <cxf.version>3.1.9</cxf.version>
 15     </properties>
 16   <dependencies>
 17     <dependency>
 18       <groupId>junit</groupId>
 19       <artifactId>junit</artifactId>
 20       <version>3.8.1</version>
 21       <scope>test</scope>
 22     </dependency>
 23     
 24     <dependency>
 25             <groupId>org.springframework</groupId>
 26             <artifactId>spring-webmvc</artifactId>
 27             <version>${spring.version}</version>
 28         </dependency>
 29         <dependency>
 30             <groupId>org.springframework</groupId>
 31             <artifactId>spring-context</artifactId>
 32             <version>${spring.version}</version>
 33         </dependency>
 34         <!-- mybatis/mybatis-plus -->
 35         <dependency>
 36             <groupId>com.baomidou</groupId>
 37             <artifactId>mybatis-plus</artifactId>
 38             <version>1.5</version>
 39         </dependency>
 40         <!-- JSTL标签类 -->
 41         <dependency>
 42             <groupId>jstl</groupId>
 43             <artifactId>jstl</artifactId>
 44             <version>1.2</version>
 45         </dependency>
 46         <!-- 格式化对象,方便输出日志 -->
 47         <dependency>
 48             <groupId>com.alibaba</groupId>
 49             <artifactId>fastjson</artifactId>
 50             <version>1.2.16</version>
 51         </dependency>
 52 
 53         <dependency>
 54             <groupId>com.fasterxml.jackson.core</groupId>
 55             <artifactId>jackson-annotations</artifactId>
 56             <version>2.8.1</version>
 57         </dependency>
 58 
 59         <dependency>
 60             <groupId>com.fasterxml.jackson.core</groupId>
 61             <artifactId>jackson-core</artifactId>
 62             <version>2.8.1</version>
 63         </dependency>
 64         <dependency>
 65             <groupId>com.fasterxml.jackson.core</groupId>
 66             <artifactId>jackson-databind</artifactId>
 67             <version>2.8.1</version>
 68         </dependency>
 69 
 70         <dependency>
 71             <groupId>org.codehaus.jackson</groupId>
 72             <artifactId>jackson-mapper-asl</artifactId>
 73             <version>1.9.13</version>
 74         </dependency>
 75 
 76         <!-- 上传组件包 -->
 77         <dependency>
 78             <groupId>commons-fileupload</groupId>
 79             <artifactId>commons-fileupload</artifactId>
 80             <version>1.3.1</version>
 81         </dependency>
 82         <dependency>
 83             <groupId>commons-io</groupId>
 84             <artifactId>commons-io</artifactId>
 85             <version>2.4</version>
 86         </dependency>
 87         <dependency>
 88             <groupId>commons-codec</groupId>
 89             <artifactId>commons-codec</artifactId>
 90             <version>1.9</version>
 91         </dependency>
 92         <dependency>
 93             <groupId>commons-logging</groupId>
 94             <artifactId>commons-logging</artifactId>
 95             <version>1.2</version>
 96         </dependency>
 97         <dependency>
 98             <groupId>javax.servlet</groupId>
 99             <artifactId>servlet-api</artifactId>
100             <version>2.5</version>
101         </dependency>
102         
103         <!-- cxf的jar包 -->
104         <dependency>
105             <groupId>org.apache.cxf</groupId>
106             <artifactId>cxf-rt-frontend-jaxws</artifactId>
107             <version>${cxf.version}</version>
108         </dependency>
109         <dependency>
110             <groupId>org.apache.cxf</groupId>
111             <artifactId>cxf-rt-transports-http</artifactId>
112             <version>${cxf.version}</version>
113         </dependency>
114   </dependencies>
115   <build>
116     <finalName>soaclient</finalName>
117   </build>
118 </project>

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 4     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5     id="WebApp_ID" version="3.1">
 6     <display-name>zkclient</display-name>
 7 
 8     <context-param>
 9         <param-name>contextConfigLocation</param-name>
10         <param-value>classpath:spring-cxf-config.xml</param-value>
11     </context-param>
12 
13     <listener>
14         <description>spring监听器</description>
15         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
16     </listener>
17 
18     <filter>
19         <filter-name>characterEncodingFilter</filter-name>
20         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
21         <init-param>
22             <param-name>encoding</param-name>
23             <param-value>UTF-8</param-value>
24         </init-param>
25         <init-param>
26             <param-name>forceEncoding</param-name>
27             <param-value>true</param-value>
28         </init-param>
29     </filter>
30 
31     <filter-mapping>
32         <filter-name>characterEncodingFilter</filter-name>
33         <url-pattern>/*</url-pattern>
34     </filter-mapping>
35 
36     <servlet>
37         <description>spring mvc servlet</description>
38         <servlet-name>springMvc</servlet-name>
39         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
40         <init-param>
41             <param-name>contextConfigLocation</param-name>
42             <param-value>classpath:spring-mvc.xml</param-value>
43         </init-param>
44         <init-param>
45             <param-name>activeReverseAjaxEnabled</param-name>
46             <param-value>true</param-value>
47         </init-param>
48         <load-on-startup>1</load-on-startup>
49     </servlet>
50     <servlet-mapping>
51         <servlet-name>springMvc</servlet-name>
52         <url-pattern>*.do</url-pattern>
53     </servlet-mapping>
54     <welcome-file-list>
55         <welcome-file>index.jsp</welcome-file>
56     </welcome-file-list>
57 </web-app>

spring-mvc.xml

 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:mvc="http://www.springframework.org/schema/mvc"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 7                         http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
 8                         http://www.springframework.org/schema/mvc 
 9                         http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 
10                         http://www.springframework.org/schema/context 
11                         http://www.springframework.org/schema/context/spring-context-4.2.xsd ">
12     <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
13     <context:component-scan base-package="com.soa.web">
14         <context:include-filter type="annotation"
15             expression="org.springframework.stereotype.Controller" />
16     </context:component-scan>
17     <!-- 日期转换 必须放在<mvc:annotation-driven />前面 -->
18     <bean
19         class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
20     <mvc:annotation-driven />
21     <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
22     <bean
23         class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
24     <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
25     <bean
26         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
27         <property name="prefix" value="/WEB-INF/jsp"></property>
28         <property name="suffix" value=".jsp"></property>
29     </bean>
30 </beans>

spring-cxf-config.xml

 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:jaxws="http://cxf.apache.org/jaxws"
 4     xsi:schemaLocation=" http://www.springframework.org/schema/beans    
 5     http://www.springframework.org/schema/beans/spring-beans.xsd    
 6     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
 7     
 8     
 9     <jaxws:client id="iTestService" serviceClass="com.soa.service.ITestService"
10         address="http://127.0.0.1:8080/soaservice/webservice/testServiceImpl?wsdl" />
11 
12 </beans>   

ITestService.java 接口层

 1 package com.soa.service;
 2 import java.util.List;
 3 import javax.jws.WebService;
 4 import javax.jws.soap.SOAPBinding;
 5 import javax.jws.soap.SOAPBinding.Style;
 6 import com.soa.entity.Test;
 7 
 8 /**
 9  *
10  * Test 表数据服务层接口
11  *extends ISuperService<Test>
12  */
13 @WebService
14 @SOAPBinding(style = Style.RPC)
15 public interface ITestService  {
16     public List<Test> selectAll();
17 }

TestController.java   Controller层调用接口

 1 package com.soa.web;
 2 
 3 import javax.servlet.http.HttpServletRequest;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.beans.factory.annotation.Qualifier;
 7 import org.springframework.stereotype.Controller;
 8 import org.springframework.web.bind.annotation.RequestMapping;
 9 
10 import com.soa.service.ITestService;
11 
12 @Controller
13 @RequestMapping("test")
14 public class TestController {
15     @Autowired
16     @Qualifier("iTestService")//注入iTestService 与spring-cxf-config.xml-->jaxws:client-->id相同
17     private ITestService testService;
18        @RequestMapping("test")
19         private String toTest(HttpServletRequest request){
20             request.setAttribute("list", testService.selectAll());
21             return "/test";
22         }
23 }

 

结束...............

posted @ 2016-12-20 08:51  冰空世纪  阅读(956)  评论(0编辑  收藏  举报