CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)

1.先将ssm框架搭好

CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第1张图片

2.添加CXF的Maven

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.1.6</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-core -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>3.1.6</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-transports-http -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.1.6</version>
    </dependency>

这是cxf的maven ssm我就不贴了网上很多!

3.使用注解发布接口

CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第2张图片

4.配置实现类

CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第3张图片

## 5去写cxf 的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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        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://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.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-servlet.xml" /> 
     <!-- 自动扫描webService -->
    <context:component-scan base-package="com.jksd" />
    <!-- implementor这里的是实现类的地址-->
    <jaxws:endpoint   implementor="com.jksd.service.servicesImpi.ServicesImpi" address="/HelloWorld"/>

</beans>

6.配置web.xml

添加上

```java

	
		org.springframework.web.context.ContextLoaderListener
	
	
        CXFServlet
        org.apache.cxf.transport.servlet.CXFServlet
    
    
        CXFServlet
        /webservice/*
    

7.在appcontext.xml中引入spring-cxf.xml

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

然后启动项目去访问
http://localhost:8081/ssm_2/webservice/HelloWorld?wsdl
CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第4张图片

8.创建客户端

将Maven 上面的依赖倒进去
CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第5张图片

9.运行测试类

CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第6张图片
这里是动态调用其他的调用方式测试过没问题就不演示了!

!实体类的包名要和服务端一直 否则会报对象转换失败!下面演示下这个错误
这是实体类的包路劲不对将路径改正常后测试:
CXF整合 ssm(重点CXF实现WebService以及客户端动态调用)_第7张图片

你可能感兴趣的:(webservice,cxf,java)