boot整合xfire

最近换了项目组,框架使用的boot整合的xfire,之前没使用过xfire,所以写个例子记录下,看 前辈的帖子 整理下

pom文件     

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.4.2</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- webservice start -->
<dependency>
	<groupId>org.codehaus.xfire</groupId>
	<artifactId>xfire-all</artifactId>
	<version>1.2.6</version>
</dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<!-- webservice end -->

定义XfireServlet

package com.example.demo.config;

import org.codehaus.xfire.spring.XFireSpringServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class XfireServlet {

    @Bean
    public ServletRegistrationBean registrationBean(){
        ServletRegistrationBean registrationBean=new ServletRegistrationBean();
        registrationBean.addUrlMappings("/webservice/*");
        registrationBean.setServlet(new XFireSpringServlet());
        return registrationBean;
    }
}

创建boot-xfire.xml文件

其中<context:component-scan base-package="" />路径对应的@WebService的所在位置

 

<?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.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!--扫描被@webService的包-->
    <context:component-scan base-package="com.example.demo.webservice.impl" />
    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
    <!--<import resource="xfire.xml" />-->
    <bean id="webAnnotations" class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations" />
    <bean id="jsr181HandlerMapping" class="org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping">
        <property name="xfire" ref="xfire" />
        <property name="webAnnotations" ref="webAnnotations" />
    </bean>
</beans>

创建XfireConfig文件 引入配置文件

package com.example.demo.config;

import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;


@ImportResource(locations = {"classpath:config/boot-xfire.xml"})
@Component
public class XfireConfig {
}

创建WebApplicationContextLocator文件

package com.example.demo.config;

import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;


@Configuration
public class WebApplicationContextLocator implements ServletContextInitializer {

    private static WebApplicationContext webApplicationContext;

    public static WebApplicationContext getWebApplicationContext(){
        return webApplicationContext;
    }
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        webApplicationContext= WebApplicationContextUtils.getWebApplicationContext(servletContext);
    }
}

创建webservice

package com.example.demo.webservice;

import javax.jws.WebService;


@WebService
public interface UserWebService {

    String queryAgeLarge(int age);

}

创建webservice实现类

package com.example.demo.webservice.impl;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.webservice.UserWebService;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
import java.util.List;

/**
 * serviceName: 请求时的地址
 * name: 无用,与serviceName一致
 * targetNamespace: 命名空间 一般是包路径反过来
 */
@WebService(serviceName = "userWebService",name = "userWebService",
        targetNamespace = "http://impl.webservice.demo.example.com")
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@Service
public class UserWebServiceImpl implements UserWebService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String queryAgeLarge(int age) {
        //todo
        List<User> userList = userMapper.queryAgeLarge(age);
        JSONArray jsonArray = new JSONArray(userList);
        String json = jsonArray.toString();
        return returnXml("200",json);
    }

    private String returnXml(String code,String data){
        return "<resp><code>"+code+"</code>"+"<data>"+data+"</data>"+"</resp>";
    }
}

项目启动,但是报错

报错一

Offending resource: class path resource [config/boot-xfire.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from class path resource [org/codehaus/xfire/spring/xfire.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 24; 

Attribute "singleton" must be declared for element type "bean".

解决:用好压打开本地仓库的 org\codehaus\xfire\xfire-all\1.2.6 路径的 xfire-all-1.2.6.jar 包,将xfire.xml和xfireXmlBeans.xml文件的属性singletnotallow="true"​删除,保存后更新

报错二

Cannot convert value of type 'org.codehaus.xfire.spring.editors.ServiceFactoryEditor' to required type 'java.lang.Class' for property 'customEditors[org.codehaus.xfire.service.ServiceFactory]': PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value of type 'org.codehaus.xfire.spring.editors.ServiceFactoryEditor'

解决:用好压打开本地仓库的 org\codehaus\xfire\xfire-all\1.2.6 路径的 xfire-all-1.2.6.jar 包,将customEditors.xml文件的<map></map>标签内信息换成 <entry key="org.codehaus.xfire.service.ServiceFactory" value="org.codehaus.xfire.spring.editors.ServiceFactoryEditor"></entry>  保存后更新

接口发布

项目启动,浏览器访问

 接口调用

XfireClient类
package com.example.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.codehaus.xfire.client.Client;
import org.springframework.stereotype.Component;

import java.net.URL;


@Component
@Slf4j
public class XfireClient {
    public static String xfireSendMsg(String xfireUrl, String namespaceURI, String method, int reqXml) throws Exception {
        // 创建服务
        Client client = new Client(new URL(xfireUrl));
        // 设置调用的方法和方法的命名空间
        client.setProperty(namespaceURI, method);
        // 通过映射获得结果
        Object[] result = new Object[0];
        try {
            result = client.invoke(method, new Object[]{reqXml});
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        String xml = (String) result[0];
        log.info("响应报文 : {}", xml);
        return xml;
    }
}
controller类
package com.example.demo.controller;

import com.example.demo.config.XfireClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/testXfire")
@Slf4j
public class TestXfireController {

    @Autowired
    private XfireClient client;

    @RequestMapping("/test")
    public String test() throws Exception {
        String queryAgeLarge = client.xfireSendMsg("http://localhost:8888//webservice/userWebService?wsdl",
                "http://impl.webservice.demo.example.com",
                "queryAgeLarge",
                1);
        log.info("输出日志={}",queryAgeLarge);
        return queryAgeLarge;
    }
}
postman调用

可见xml信息正常接收到!

不足之处,还请之处!!!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/492487.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

上位机图像处理和嵌入式模块部署(qmacvisual图像识别)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 所谓图像识别&#xff0c;就是对图像进行分类处理&#xff0c;比如说判断图像上面的物体是飞机、还是蝴蝶。在深度学习和卷积神经网络CNN不像现在这…

企微获客助手功能,行为触发如何实现回传的?

获客助手&#xff0c;这个听起来就相当酷炫的名字&#xff0c;它实际上是一个帮助企业将推广流量快速导入企业微信的神器。通过它&#xff0c;企业可以吸引越来越多的用户加为好友&#xff0c;从而建立起更紧密的客户关系。但是&#xff0c;如何进一步提升导入企业微信的流量质…

IntersectionObserver:实现滚动动画、懒加载、虚拟列表

认识 浏览器自带的适用于 「监听元素与视窗交叉状态」 的观察器&#xff1a;「IntersectionObserver&#xff08;交叉观察器&#xff09;」 IntersectionObserver 是一种 JavaScript API&#xff0c;它提供了一种异步监测元素与其祖先容器或视口之间交叉状态的方法。简单来说&…

数据库备份工具(实现数据定时覆盖)

数据库备份工具&#xff08;实现数据定时覆盖&#xff09; 永远热爱&#xff0c;永远执着&#xff01; 工具介绍 自动化测试数据库更新调度程序 这段 Python 脚本自动化了每天定时从生产数据库更新测试数据库的过程。它利用了 schedule 库来安排并执行每天指定时间的更新任务…

(vue)el-table表格回显返回的已勾选的数据

(vue)el-table表格编辑时回显返回的已勾选的数据 tableData数据&#xff1a; el-tableref"multipleTable":data"tableData"... >...<el-table-column prop"result" label"相关.." align"center" width"220"…

【Java程序设计】【C00344】基于Springboot的船舶维保管理系统(有论文)

基于Springboot的船舶维保管理系统&#xff08;有论文&#xff09; 项目简介项目获取开发环境项目技术运行截图 项目简介 项目获取 &#x1f345;文末点击卡片获取源码&#x1f345; 开发环境 运行环境&#xff1a;推荐jdk1.8&#xff1b; 开发工具&#xff1a;eclipse以及i…

NX二次开发判断两对象是否相连(相交,相离)

一、概述 最近学习如何判断两根曲线是否连接&#xff08;不是相交&#xff0c;两条直线有一个端点重合&#xff09;&#xff0c;网上说到两种方法&#xff0c;一种是第一种方法&#xff0c;UF_MODL_ask_minimum_dist_3函数判断两个对象的距离&#xff0c;测得的距离等于零&…

【python】进程和线程

文章目录 进程创建进程os.fork() - 只适用于linux/unix/macmultiprocessing模块Process 类Pool进程池进程间通信队列queue常见用法管道pipes线程创建线程线程间通信互斥锁队列进程 任务管理器中一个任务就是一个进程 创建进程 os.fork() - 只适用于linux/unix/mac multipr…

Halcon与C#联合开发——1.读取图片、图像二值化

在vs中引入halcon控件 修改目标平台为 x64 拖出三个控件 代码展示 using System; using System.Windows.Forms; //引用支持halcon的命名空间 using HalconDotNet;namespace _1.HalconDisplay {public partial class Form1 : Form {// HObject 是Halcon库中表示图像和其他图形…

CentOS7下nginx部署测试

nginx部署测试 #安装程序和依赖yum install -y vim net-tools wgetyum -y install gcc pcre-devel zlib-devel openssl openssl-devel #下载nginx mkdir /opt/nginx cd /opt/nginx wget https://nginx.org/download/nginx-1.20.2.tar.gz#解压 tar zxvf nginx-1.20.2.tar.gz c…

Docker容器与虚拟化技术:OpenEuler 部署 Docker UI

目录 一、实验 1.环境 2.OpenEuler 部署 docker-compose-ui 2.OpenEuler 部署 docker ui 3.使用cpolar内网穿透 二、问题 1.docker run -w 的作用 一、实验 1.环境 &#xff08;1&#xff09;主机 表1 主机 系统架构版本IP备注LinuxopenEuler22.03 LTS SP2 192.168…

PMBOK第八版、项目管理AI标准...PMI标准今年有这些进展

项目管理实践标准不断在演变&#xff0c;PMI作为项目管理领域的权威机构&#xff0c;一直致力于与全球各行各业的项目实践者一同探索和研究最新的行业标准&#xff0c;确保PMI标准符合全球项目专业人士当前能力建设与职业发展的需要。 今年以来&#xff0c;我们发布了一系列PM…

Python提取本体文件的数据

运行结果&#xff1a; 使用replace函数去除前缀。 查找OWL的对象属性&#xff1a; 输出结果&#xff1a; 出现最后这个的原因&#xff1a; 修改程序&#xff1a; 最后的输出结果&#xff1a; 这个解析之后是这个样子的&#xff1a;

考研数学|《1800》《1000》《880》《660》最佳搭配使用方法

直接说结论&#xff1a;基础不好先做1800、强化之前660&#xff0c;强化可选880/1000题。 首先&#xff0c;传统习题册存在的一个问题是题量较大&#xff0c;但难度波动较大。《汤家凤1800》和《张宇1000》题量庞大&#xff0c;但有些题目难度不够平衡&#xff0c;有些过于简单…

代码随想录训练营第59天 | LeetCode 503.下一个更大元素II、LeetCode 42. 接雨水

目录 LeetCode 503.下一个更大元素II 文章讲解&#xff1a;代码随想录(programmercarl.com) 视频讲解&#xff1a;单调栈&#xff0c;成环了可怎么办&#xff1f;LeetCode&#xff1a;503.下一个更大元素II_哔哩哔哩_bilibili 思路 ​​​​​​LeetCode 42. 接雨水 文章…

Compute Express Link (CXL): An Open Interconnect for Cloud Infrastructure——论文阅读

DAC 2023 Paper CXL论文阅读笔记整理 背景 Compute Express Link是一种开放的行业标准互连&#xff0c;在PCI Express&#xff08;PCIe&#xff09;之上提供缓存和内存语义&#xff0c;具有资源池和织物功能。本文探讨了CXL在解决云基础设施中的一些挑战方面的作用。 CXL主要…

数据化运营09 抓住问题关键:用相关性分析拆解多个影响因素

前一讲&#xff0c;和你探讨了多维分析的方法&#xff0c;通过多维分析来寻找指标变化的原因。当我们找到问题的原因时&#xff0c;自然会进一步思考一个问题&#xff1a;指标变化的原因这么多&#xff0c;决定问题的关键因素又是哪个呢&#xff1f; 需要专栏原数据进行实操的同…

Linux小程序——进度条

前言&#xff1a;哈喽小伙伴们&#xff0c;经过我们对多个Linux基本开发工具的学习之后&#xff0c;对于Linux的使用也算是更上一层楼。 所以这篇文章&#xff0c;我们就尝试使用我们学过的Linux知识来写一个小程序——进度条&#xff0c;达到实践以及加深知识映像的效果。 目…

智能文档处理技术综述

一、 智能文档处理介绍 智能文档处理&#xff08;Intelligent Document Processing, IDP&#xff09;是利用人工智能&#xff08;AI&#xff09;、机器学习&#xff08;ML&#xff09;、计算机视觉&#xff08;CV&#xff09;、自然语言处理&#xff08;NLP&#xff09;等技术…

POJ3037 + HDU-6714

两道最短路好题 POJ3037 手玩一下 发现每一点的速度可以直接搞出来&#xff0c;就是pow(2,h[1][1]-h[i][j])*V 那么从这个点出发到达别的点的耗费的时间都是上面这个数的倒数&#xff0c;然后直接跑最短路就好了 #include<iostream> #include<vector> #include<…