springboot配置cxf

1.引入两个需要的jar

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.1.12</version>
        </dependency>

2.配置webservice类

package com.btw.court.webService;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface PayWebService {

    @WebMethod
    String say(@WebParam(name="arg0")String arg0);

}

3.配置webservice实现类

package com.btw.court.webService.impl;

import com.btw.court.webService.PayWebService;

import javax.jws.WebService;

@WebService(targetNamespace = "http://say.com")//对应wsdl中的命名空间xmlns:tns
public class PayWebServiceImpl implements PayWebService {

    @Override
    public String say(String arg0) {
        return null;
    }

}

4.配置springboot配置类

package com.btw.court.config;

import com.btw.court.webService.PayWebService;
import com.btw.court.webService.impl.PayWebServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class WebServiceConfig {

    @Bean//发布服务名称,可以访问该路径查看拥有的webservice
    public ServletRegistrationBean dispathcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/service/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public PayWebService payWebService() {
        return new PayWebServiceImpl();
    }

    /**
     * 绑定接口类,描述接口实现方法,以及接口名称.如果有多个接口需要实现,可以添加多个该方法(设置方法名不同,发布路径不同即可)
     * @return
     */
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), payWebService());
        endpoint.publish("/ws");
        return endpoint;
    }
}

此时,我们输入http://ip:port/service,可以看到如下图所示内容。左侧马赛克为接口包含的方法,右侧为接口的描述,包括发布地址、wsdl和命名空间。

点击wsdl的路径,可以看到接口的详细描述。

原文地址:https://www.cnblogs.com/yxth/p/10436377.html

时间: 2024-08-30 11:56:31

springboot配置cxf的相关文章

SpringBoot配置详解

SpringBoot配置详解 SpringBoot自动化配置 在上一节中我们使用Spring Boot实现了一个简单的RESTful API应用,在实现过程中,除了Maven的pom文件的一些配置,我们没有做任何其他的配置,这就是Spring Boot的自动化配置带来的好处,但是,我们还需要了解如何在Spring Boot中修改这些自动化配置的内容,以应对一些特殊的场景需求. 配置文件—Spring Boot支持YAML配置文件和properties配置文件 Spring Boot的默认配置文件

SpringBoot配置属性之NOSQL

SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之NOSQL SpringBoot配置属性之MQ SpringBoot配置属性之Security SpringBoot配置属性之Migration SpringBoot配置属性之其他 另外附上个人关于springboot的一些文章 SpringBoot前世今生 SpringBoot集成mybatis S

SpringBoot配置属性之MQ

SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之NOSQL SpringBoot配置属性之MQ SpringBoot配置属性之Security SpringBoot配置属性之Migration SpringBoot配置属性之其他 另外附上个人关于springboot的一些文章 SpringBoot前世今生 SpringBoot集成mybatis S

SpringBoot配置属性之其他

SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之NOSQL SpringBoot配置属性之MQ SpringBoot配置属性之Security SpringBoot配置属性之Migration SpringBoot配置属性之其他 另外附上个人关于springboot的一些文章 SpringBoot前世今生 SpringBoot集成mybatis S

SpringBoot配置属性之Migration

SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之NOSQL SpringBoot配置属性之MQ SpringBoot配置属性之Security SpringBoot配置属性之Migration SpringBoot配置属性之其他 另外附上个人关于springboot的一些文章 SpringBoot前世今生 SpringBoot集成mybatis S

SpringBoot配置全局异常捕获

1 SpringBoot配置全局的异常捕获 项目的说明 配置thymeleaf作为视图模板 ExceptionController.java模拟测试用 MyAjaxExceptionHandler.java捕获到异常以ajax形式返回 MyExceptionHandler.java捕获到异常以页面形式返回 ajaxerror.html这个是测试返回ajax异常的页面 error.html以页面形式返回的异常到这个页面 1.1 页面跳转形式 1.1.1 配置 MyExceptionHandler.

SpringBoot配置devtools实现热部署

SpringBoot配置devtools实现热部署 spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用. devtools的原理 深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为restart ClassLoader,这样在有代码更改的时候,原来的resta

腾讯云域名申请+ssl证书申请+springboot配置https

阿里云域名申请 域名申请比较简单,使用微信注册阿里云账号并登陆,点击产品,选择域名注册 输入你想注册的域名 进入域名购买页面,搜索可用的后缀及价格,越热门的后缀(.com,.cn)越贵一般,并且很可能已经被注册. 最后,付款购买即可. 申请ssl证书 还是进入首页,点击产品按钮,在下拉菜单中选择ssl证书,进入后点立即购买,在下图中做如下选择 ssl证书是要与域名绑定的,按要求填好域名和邮箱,密码可以不填 填写好,选择下一步,然后选择手动dns,提交,然后查看证书详情. 进入域名解析页面,找到你

使用 SpringBoot 配置发送邮件功能

1.使用 SpringBoot 配置发送邮件功能 项目总体结构 用户表设计 SET FOREIGN_KEY_CHECKS=0; CREATE DATABASE sample; USE sample; set names utf8; -- ---------------------------- -- Table structure for tab_mail -- ---------------------------- DROP TABLE IF EXISTS `tab_mail`; CREAT