boot整合xfire

news2024/9/30 23:28:53

最近换了项目组,框架使用的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.coloradmin.cn/o/1550053.html

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

相关文章

渐变色x轴换行柱状图

// 系统上云率const optionBar {title: {text: 系统上云率,left: left,textStyle: {color: "#fff",fontSize: 14,fontWeight: 650,align: "center",},},color: [#32C5FF, #00F766, #EECB5F],grid: {top: 40,bottom: 0,},legend: { // 控制图例组件show: …

力扣面试150 删除有序数组中的重复项 双指针

Problem: 26. 删除有序数组中的重复项 思路 &#x1f469;‍&#x1f3eb; 三叶题解 复杂度 时间复杂度: O ( n ) O(n) O(n) 空间复杂度: O ( 1 ) O(1) O(1) Code class Solution {public int removeDuplicates(int[] nums) {int j 0, n nums.length;for(int i 0;…

后端前行Vue之路(二):模版语法之插值与指令

1.概述 Vue.js的模板语法是一种将Vue实例的数据绑定到HTML文档的方法。Vue的模板语法是一种基于HTML的扩展&#xff0c;允许开发者将Vue实例中的数据绑定到HTML元素&#xff0c;以及在HTML中使用一些简单的逻辑和指令。Vue.js 基于 HTML 的模板语法允许开发者声明式地将 DOM 绑…

从MVC 到DDD 架构

目录 一、前言 二、MVC架构 三、DDD架构 四、我为什么会使用DDD&#xff1f; 五、DDD架构分层 一、前言 最近在做一个项目&#xff0c;使用的是DDD架构思&#xff0c;觉得很不错&#xff0c;在此记录下。 二、MVC架构 MVC是一种经典的软件架构模式&#xff0c;主要用于…

GEE:将分类特征和标签提取到样本点,并以(csv/shp格式)下载到本地

作者:CSDN @ _养乐多_ 本文将介绍在Google Earth Engine(GEE)平台上,下载用于机器学习分类或者回归的样本点数据,样本点数据携带了分类特征和标签信息,可以以csv格式或者SHP格式。 结果如下图所示, 文章目录 一、核心函数1.1 采样1.2 下载函数二、代码链接三、完整代码…

Go-js,css,html压缩和混淆(可直接使用)

前提条件: 本地安装nodejs环境然后配置全局环境变量。 运行以下命令安装uglify压缩工具 npm install uglify-js -g 测试是否安装成功 uglifyjs -v 使用方式: 根据不同的操作系统取对应的压缩工具,然后将压缩工具放到项目根目录下,然后执行即可 工具文件: https://gitee.com…

GPT提示词分享 —— 口播脚本

可用于撰写视频、直播、播客、分镜头和其他口语内容的脚本。 提示词&#x1f447; 请以人的口吻&#xff0c;采用缩略语、成语、过渡短语、感叹词、悬垂修饰语和口语化语言&#xff0c;避免重复短语和不自然的句子结构&#xff0c;撰写一篇关于 [主题] 的文章。 GPT3.5&#…

【论文速读】| 对大语言模型解决攻击性安全挑战的实证评估

本次分享论文为&#xff1a;An Empirical Evaluation of LLMs for Solving Offensive Security Challenges 基本信息 原文作者&#xff1a;Minghao Shao, Boyuan Chen, Sofija Jancheska, Brendan Dolan-Gavitt, Siddharth Garg, Ramesh Karri, Muhammad Shafique 作者单位&a…

喜讯!聚铭网络荣获《日志分类方法及系统》发明专利

近日&#xff0c;聚铭网络又喜获一项殊荣&#xff0c;其申报的《日志分类方法及系统》发明专利成功获得国家知识产权局的授权&#xff0c;正式荣获国家发明专利证书。 在信息化时代&#xff0c;网络安全问题日益凸显&#xff0c;日志分析作为保障网络安全的重要手段&#xff…

【机器学习之旅】概念启程、步骤前行、分类掌握与实践落地

&#x1f388;个人主页&#xff1a;豌豆射手^ &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏 &#x1f917;收录专栏&#xff1a;机器学习 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共同学习、交流进…

【旅游景点项目日记 | 第一篇】项目服务架构、数据库表设计

Gitee仓库地址&#xff1a;travel-server&#xff1a;景点旅游项目服务端 文章目录 1.项目服务架构2.数据库设计2.1用户服务—travel_ums2.1.1 ums_user—用户表 2.2景点服务—travel_ams2.2.1 ams_attraction—景点表1.2.2 ams_resource_type—资源类型表 2.3票务服务—trabel…

人工智能的决策树介绍

决策树模型 决策树基于“树”结构进行决策 每个“内部结点”对应于某个属性上的“测试”每个分支节点对应于该测试的一种可能结果&#xff08;即属性的某个取值&#xff09;每个“叶结点”对应于一个“预测结果” 学习过程&#xff1a;通过对训练样本的分析来确定“划分属性”…

如何在jupyter使用新建的虚拟环境以及改变jupyter启动文件路径。

对于刚刚使用jupyter的新手来说&#xff0c;经常不知道如何在其中使用新建的虚拟环境内核&#xff0c;同时&#xff0c;对于默认安装的jupyter&#xff0c;使用jupyter notebook命令启动 jupyter 以后往往默认是C盘的启动路径&#xff0c;如下图所示&#xff0c;这篇教程将告诉…

vector类(一)

文章目录 vector介绍和使用1.vector的介绍2.vector的使用2.1 vector的定义2.2 vector iterator的使用2.3 vector空间增长问题2.4 vector增删查改2.5 vector迭代器失效问题 3.vector 在OJ中的使用 vector介绍和使用 1.vector的介绍 vector是表示 可变大小数组的 序列容器。 就…

Matlab|【免费】面向多微网网络结构规划的大规模二进制矩阵优化算法

目录 1 主要内容 节点故障网络拓扑变化示意 约束条件 目标函数 3 结果一览 4 下载链接 1 主要内容 当前电力系统中微电网逐步成为发展的主力军&#xff0c;微网中包括分布式电源和负荷&#xff0c;单一的微电网是和外部电源进行连接&#xff0c;即保证用电的效益性&#…

手机短信验证码自动转发到服务器

今天写一个自动化处理程序&#xff0c;需要验证码登录&#xff0c;怎么样把手机收到的短信自动转发到服务器接口呢&#xff1f; 利用ios手机快捷指令的功能 打开快捷指令点击中间自动化点击右上角号选择信息信息包含选取&#xff0c;输入验证码选择立即执行点击下一步按下图配…

SpringBoot集成WebSocket实现简单的多人聊天室

上代码—gitee下载地址&#xff1a; https://gitee.com/bestwater/Spring-websocket.git下载代码&#xff0c;连上数据库执行SQL&#xff0c;就可以运行&#xff0c;最终效果

17、GateWay和Sentinel继承实现服务限流

注&#xff1a;本篇文章主要参考周阳老师讲解的cloud进行整理的&#xff01; 1、需求说明 cloudalibaba-sentinel-gateway9528 保护 cloudalibaba-provider-payment9001 2、启动nacos服务器8848 startup.cmd -m standalone 3、启动sentinel服务器8080 java -jar sentinel-dash…

PPT没保存怎么恢复?3个方法(更新版)!

“我刚做完一个PPT&#xff0c;正准备保存的时候电脑没电自动关机了&#xff0c;打开电脑后才发现我的PPT没保存。这可怎么办&#xff1f;还有机会恢复吗&#xff1f;” 在日常办公和学习中&#xff0c;PowerPoint是制作演示文稿的重要工具。我们会在各种场景下使用它。但有时候…

【办公类-21-11】 20240327三级育婴师 多个二级文件夹的docx合并成docx有页码,转PDF

背景展示&#xff1a;有页码的操作题 背景需求&#xff1a; 实操课终于全部结束了&#xff0c;把考试内容&#xff08;docx&#xff09;都写好了 【办公类-21-10】三级育婴师 视频转文字docx&#xff08;等线小五单倍行距&#xff09;&#xff0c;批量改成“宋体小四、1.5倍行…