WebService--CXF与Spring的整合(jaxws:endpoint形式配置)

一、CXF与Spring整合(jaxws:endpoint形式配置)

工具要点:idea、maven

1.新建一个maven项目

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.wp.learn.webservice.webserver</groupId>
  <artifactId>webserver</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <cxf.version>2.2.3</cxf.version>
    <spring.version>3.0.2.RELEASE</spring.version>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-testutils</artifactId>
      <version>${cxf.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-local</artifactId>
      <version>${cxf.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http-jetty</artifactId>
      <version>${cxf.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-jdk14</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>${cxf.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${spring.version}</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

</project>

pom.xml

2.web.xml文件中配置CXFServlet以及Spring容器,配置Spring的配置文件,配置webservice的配置文件

web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

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

</web-app>

web.xml

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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
    <context:component-scan base-package="com.wp.learn.webservice"></context:component-scan>
    <!-- 导入其他配置文件 -->
    <import resource="applicationContext-ws.xml" />

</beans>

applicationContext-ws.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:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <jaxws:endpoint id="helloWebservice" implementor="#helloServiceImpl"
                    address="/hello" />
</beans>

接口HelloService:

Impl类HelloServiceImpl:

情况一、如果Impl类的注解是@Webservice,implementor需要写完全路径

情况二、Impl类注解是@Service,implementor只需“#”号加bean的id名

时间: 2024-10-29 22:22:21

WebService--CXF与Spring的整合(jaxws:endpoint形式配置)的相关文章

webservice cxf与spring详解

wsdl文档结构图 JDK方式开发 server端代码 package server; import javax.jws.WebMethod; import javax.jws.WebService; /**  *   *   * SEI:Service Endpoint Interface 发布的服务接口  *  */ @WebService public interface HelloWS { @WebMethod     public String sayHello(String name

spring在整合框架中常用配置的bean

1 数据源 1.1spring默认的数据源DriverManagerDatasource <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"><

通过Spring Boot整合Mybatis分析自动配置详解

前言 SpringBoot凭借"约定大于配置"的理念,已经成为最流行的web开发框架,所以有必须对其进行深入的了解:本文通过整合Mybatis类来分析SpringBoot提供的自动配置(AutoConfigure)功能,在此之前首先看一个整合Mybatis的实例. SpringBoot整合Mybatis 提供SpringBoot整合Mybatis的实例,通过Mybatis实现简单的增删改查功能: 1.表数据 CREATE TABLE `role` (  `note` varchar(2

spring boot整合cxf发布和调用webservice

一.前言 说起web service最近几年restful大行其道,大有取代传统soap web service的趋势,但是一些特有或相对老旧的系统依然使用了传统的soap web service,例如银行.航空公司的机票查询接口等.本博客主要讲解得是spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务本案例使用maven方式二.编码核心文件清单1.pom.xml <?xml version="1.0"

Web Service学习-CXF与Spring整合为JavaEE应用发布WebService(三)

CXF与Spring整合,分两个方面给大家介绍: 1,在传统ssh项目基础上添加Web Service 赋值CXF的jar包 在web.xml配置文件中导入CXF的核心控制器:CXFServlet 在Spring配置文件中导入CXF提供Schema,xml配置文件 在Spring配置文件中使用jaxws:endpoint元素来暴露Web Service 如果要添加拦截器,在jaxws:endpoint元素里添加 inInterceptors,outInterceptors子元素 2,远程调用We

WebService—CXF整合Spring实现接口发布和调用过程2

一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>2.7.18</version> </dependency> <de

WebService—CXF整合Spring实现接口发布和调用过程

一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>2.7.18</version> </dependency> <de

webservice的cxf和spring整合发布

1.新建一个web项目 2.导入cxf相应的jar包,并部署到项目中 3.服务接口 1 package com.xiaostudy; 2 3 /** 4 * @desc 服务器接口 5 * @author xiaostudy 6 * 7 */ 8 public interface Test_service { 9 10 public String getNumber(String number); 11 12 } 4.服务接口实现类 1 package com.xiaostudy; 2 3 im

CXF+WS-Security+Spring WebService服务器端+客户端及注意问题

项目中要用到webservice,刚听到的时候还挺开心的,因为我之前接触过,想来应该不是很难,. 谁料,事实不是这样的....,让我费了个好劲啊. 不说了,下面上代码,这是入门级的,所以会比较详细,仔细看: 服务器端: 1.接口+实现类 //接口 package com.ekservice.service; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax