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 {@Beanpublic 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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://www.springframework.org/schema/contexthttp://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;}@Overridepublic 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 {@Autowiredprivate UserMapper userMapper;@Overridepublic String queryAgeLarge(int age) {//todoList<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 {@Autowiredprivate 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.mzph.cn/news/775703.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java | 日期天数计算

大家可以关注一下专栏&#xff0c;方便大家需要的时候直接查找&#xff0c;专栏将持续更新~ 题目描述 编写一个Java程序&#xff0c;用于输入一个日期&#xff08;包括年、月、日&#xff09;&#xff0c;然后判断这一天是这一年的第几天。 程序需要接收一个表示日期的字符…

Python爬虫入门:从网站爬取文章内容并保存到本地文件

目录 前言 准备工作 简单爬虫实现 注意事项 爬虫伦理与合法性 总结 前言 在互联网时代&#xff0c;数据是宝贵的资源。然而&#xff0c;当需要从海量网站中抓取数据时&#xff0c;手动操作显然不切实际。这时&#xff0c;爬虫技术应运而生&#xff0c;成为我们获取数据的…

OSG编程指南<二十一>:OSG视图与相机视点更新设置及OSG宽屏变形

1、概述 什么是视图?在《OpenGL 编程指南》中有下面的比喻,从笔者开始学习图形学就影响深刻,相信对读者学习场景管理也会非常有帮助。 产生目标场景视图的变换过程类似于用相机进行拍照,主要有如下的步骤: (1)把照相机固定在三脚架上,让它对准场景(视图变换)。 (2)…

详细分析java.io.EOFException: readObject: unexpected end of file的解决方法

目录 前言1. 问题所示2. 原理分析3. 解决方法4. 彩蛋前言 以下问题涉及知识点推荐阅读 详细分析Java中的分布式任务调度框架 XXL-Job出现 Caused by: java.lang.NumberFormatException: For input string: “Error“ 解决方法(全)java框架 零基础从入门到精通的学习路线 附开…

【爬虫基础】第4讲 GET与POST请求

GET请求 GET请求是一种HTTP方法&#xff0c;用于向服务器获取&#xff08;或读取&#xff09;数据。它是Web开发中最常用的请求方式之一。对于GET请求&#xff0c;客户端向服务器发送一个HTTP请求&#xff0c;服务器返回请求的资源。GET请求通常用于获取静态资源&#xff0c;比…

c#基础-引用类型和值类型的区别

在C#中,数据类型分为两类:值类型和引用类型。 值类型:直接存储数据,分配在栈(Stack)上。常见的值类型包括基本数据类型(int, float, double等),结构体(struct),枚举(enum)等。 引用类型:存储数据的引用和对象,分配在托管堆(Heap)上。常见的引用类型包括类(cla…

记录关于智能家居的路程的一个bug___Segmentation fault(段错误)

前言 其实发生段错误的情况有很多&#xff1a; 其实在项目的开发中最有可能的错误就是①和②&#xff0c;考虑到本项目数组用的比较少&#xff0c;所以主要是考虑错误①指针的误用。 有时候错误就是那么离谱&#xff0c;声音也算是一种设备&#xff1f;&#xff1f;&#xff…

35.HarmonyOS App(ArkUI)使用父组件@Builder装饰的方法初始化子组件@BuilderParam报错

HarmonyOS App(ArkUI)使用父组件Builder装饰的方法初始化子组件BuilderParam报错 Type void is not assignable to type () > void. <tsCheck> 去掉括号()就可以了 装饰器&#xff1a; 用于装饰类、结构、方法以及变量&#xff0c;并赋予其特殊的含义。如上述示例中En…

Linux 内核工具 iptables 配置TCP/UDP端口转发(命令参考)

1、配置TCP端口转发 把本机20000/TCP端口转发到7.7.7.7:20000 iptables -t nat -A PREROUTING -p tcp --dport 20000 -j DNAT --to-destination 7.7.7.7:20000 iptables -t nat -A POSTROUTING -j MASQUERADE 2、配置UDP端口转发 把本机20000/UDP端口转发到7.7.7.7:20000 i…

SpringBoot实现RabbitMQ的简单队列(SpringAMQP 实现简单队列)

文章目录 1. 前言2. Basic Queue 简单队列模型2.1 父工程导入依赖2.2 消息发送2.2.1 消息发送方必要的配置2.2.2 发消息 3. 消息接收3.1 消息接收方必要的配置3.2 接收消息 1. 前言 SpringAMQP 是基于 RabbitMQ 封装的一套模板&#xff0c;并且还利用 SpringBoot 对其实现了自…

2024.3.26学习总结

一&#xff0c;正则匹配 正则匹配是用来搜索&#xff0c;匹配&#xff0c;替换的一种字符串模式&#xff0c;使用正则匹配可以让搜索匹配的语句更加简洁&#xff0c;在php中会使用一些函数来处理正则匹配 常用的语法&#xff1a; 字符类 [abc]: 匹配单个字符a、b或c[^abc]: 匹…

DevSecOps平台架构系列-互联网企业私有化DevSecOps平台典型架构

目录 一、概述 二、私有化DevSecOps平台建设思路 2.1 采用GitOps公有云建设 2.2 采用GitOps私有云建设 2.3 总结 三、GitOps及其生态组件 3.1 采用GitOps的好处 3.1.1 周边生态系统齐全 3.1.2 便于自动化的实现 3.1.3 开发人员属性GitOps 3.2 GitOps部分生态组件介绍…

搜维尔科技【应急推演】虚拟仿真技术的发展为煤炭矿井的安全生产找到新的出口

煤炭矿井的安全生产一直是我国关注的重大事项&#xff0c;保证煤炭矿井的安全生产&#xff0c;减少人员伤亡等不可逆的损失成为重中之重。虚拟仿真技术的发展为煤炭矿井的安全生产找到了新的出口。依托虚拟仿真技术&#xff0c;对煤炭矿井进行实时的生产监测&#xff0c;对矿井…

PTA 道路管制

乌拉乌拉国有n个城市和m条道路&#xff0c;城市编号为1∼n。由于乌拉乌拉国每一个城市都在创城&#xff08;创建文明城市&#xff09;&#xff0c;因此&#xff0c;城市之间的道路通行施行道路交通管制&#xff1a; 已知从城市ui​到城市vi​的道路&#xff0c;需要时间ti​。…

华为昇腾asend

昇腾Ascend C编程语言 Ascend C原生支持C/C编程规范&#xff0c;通过多层接口抽象、并行编程范式、孪生调试等技术&#xff0c;极大提高了算子的开发效率&#xff0c;帮助AI 参考文章 手把手教你在昇腾平台上搭建PyTorch训练环境 - 哔哩哔哩 (bilibili.com)https://www.bilibi…

科普 | Runes 预挖矿概念

作者&#xff1a;Jacky X/推&#xff1a;zxl2102492 关于 Runes 协议的前世今生&#xff0c;可以点击阅读这篇文章 &#x1f447; 《简述 Runes 协议、发展历程及最新的「公开铭刻」发行机制的拓展讨论》 什么是传统预挖矿概念 这轮比特币生态爆发之前&#xff0c;预挖矿&…

2024 MCM数学建模美赛2024年A题复盘,思路与经验分享:资源可用性与性别比例 | 性别比例变化是否对生态系统中的其他生物如寄生虫提供优势(五)

审题 第四问让我们探究性别比例变化是否对生态系统中的其他生物如寄生虫提供优势。这里我们可以把问题简化一下&#xff0c;只探究性别比例会不会对寄生虫提供优势。因为考虑太多生物&#xff0c;会使模型更复杂&#xff0c;我这个水平处理不了这么复杂的问题&#xff0c;是我…

『大模型笔记』常见的分布式并行策略(分布式训练)

常见的分布式并行策略(分布式训练) 文章目录 一. 为什么分布式训练越来越流行二. 常见的并行策略2.1 数据并行2.2 模型并行2.3 流水并行2.4 混合并行二. 参考文献一. 为什么分布式训练越来越流行 近年来,深度学习被广泛应用到各个领域,包括计算机视觉、语言理解、语音识别、广…

Healix Protocol 的 HLX 通证预售:医疗领域的未来展望

Healix Protocol推出 HLX 通证预售&#xff0c;将带来医疗领域的重要变革。通过其区块链技术&#xff0c;Healix Protocol致力于重新定义医疗服务的可及性与负担性&#xff0c;成为医疗行业的希望之光。该项目旨在增强透明度、可及性和效率&#xff0c;推动医疗体系向更加公平和…

ripro子主题wori-child集成后台美化包(适用于设计素材站+资源下载站等)

新内容如下 1、子主题独立运行,彻底摆脱覆盖原主题文件 2、下载信息插件升级优化 3、细节优化 V1.0更新内容如下 1、同步暗黑美化、手机端美化 2、新增菜单合成幻灯片&#xff08;后台自行设置&#xff09; 3、新增公告统计 &#xff08;后台自行设置&#xff09; 4、新增…