handler name ="URLMapper" type ="java:org.apache.axis.handlers.http.URLMapper"/ > handler name ="Loc" />
0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何成功遷移到Springboot工程

科技綠洲 ? 來源:了不起 ? 作者:了不起 ? 2023-09-25 10:53 ? 次閱讀

最近在做一個老舊工程的遷移,其中一個服務(wù)端接口是使用 WebService 做的,而且用的是 Axis1.4 這種老的不能再老的框架。經(jīng)過一番探索和研究,終于成功遷移到Springboot工程里,下面跟著我一步步操作。

Axis配置文件

Axis1.4 的入口配置文件是 server-config.wsdd,在 resources 中創(chuàng)建一個 WEB-INF 文件夾,將配置文件拷貝到其中。

圖片

我們看一下配置文件的內(nèi)容:

< ?xml version="1.0" encoding="UTF-8"? >
< deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" >

    < handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/ >
    < handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/ >

    < transport name="http" >
        < requestFlow >
            < handler type="URLMapper"/ >
        < /requestFlow >
    < /transport >

    < transport name="local" >
        < responseFlow >
            < handler type="LocalResponder"/ >
        < /responseFlow >
    < /transport >

    < !-- 示例接口 -- >
    < service name="DemoService" provider="java:RPC" >
        < parameter name="className" value="com.test.webservice.DemoService"/ >
        < parameter name="allowedMethods" value="*"/ >
    < /service >

< /deployment >

主要看最后一段:聲明了一個示例接口:服務(wù)名為DemoService,映射的類為com.test.webservice.DemoService,方法名為*(通配符代表與類中的方法名一樣)

接口類

簡簡單單的一個接口類:

package com.test.webservice;

import org.springframework.stereotype.Component;

@Component
public class DemoService {

    public String test() {
        return "這是一個Axis1.4接口。";
    }

}

我們?nèi)绾伟堰@個接口發(fā)布出去呢,接著往下看。

引入依賴

我這里用的是 gradle 構(gòu)建的:

implementation('org.apache.axis:axis:1.4')
implementation('org.apache.axis:axis-jaxrpc:1.4')
implementation('axis:axis-wsdl4j:1.5.1')
implementation('commons-discovery:commons-discovery:0.5')

繼承AxisServlet

創(chuàng)建一個Servlet類,繼承AxisServlet:

package com.test.webservice.servlet;

import org.apache.axis.transport.http.AxisServlet;
import javax.servlet.annotation.WebServlet;

@WebServlet(
        urlPatterns = "/axis-services/*",
        loadOnStartup = 1,
        name = "AxisServlet"
)
public class MyAxisServlet extends AxisServlet {
}

注意,Axis默認的過濾 url 是/services/,而我這里將 urlPatterns 配置為/axis-services/,是因為工程中同時使用了 Cxf框架 ,如果使用默認配置,會與 Cxf 沖突。

重寫Axis配置工廠

網(wǎng)上拷貝的配置工廠類:

package org.apache.axis.configuration;

import org.apache.axis.AxisProperties;
import org.apache.axis.ConfigurationException;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.EngineConfigurationFactory;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.server.AxisServer;
import org.apache.axis.utils.ClassUtils;
import org.apache.axis.utils.Messages;
import org.apache.commons.logging.Log;

import javax.servlet.ServletConfig;
import java.io.InputStream;


public class EngineConfigurationFactoryServlet extends EngineConfigurationFactoryDefault {
    protected static Log log = LogFactory.getLog(EngineConfigurationFactoryServlet.class.getName());
    private ServletConfig cfg;

    public static EngineConfigurationFactory newFactory(Object param) {
        return (param instanceof ServletConfig)
                ? new EngineConfigurationFactoryServlet((ServletConfig) param)
                : null;
    }

    protected EngineConfigurationFactoryServlet(ServletConfig conf) {
        super();
        this.cfg = conf;
    }

    @Override
    public EngineConfiguration getServerEngineConfig() {
        return getServerEngineConfig(cfg);
    }

    private static EngineConfiguration getServerEngineConfig(ServletConfig cfg) {
        String configFile = cfg.getInitParameter(OPTION_SERVER_CONFIG_FILE);
        if (configFile == null) {
            configFile =
                    AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE);
        }
        if (configFile == null) {
            configFile = SERVER_CONFIG_FILE;
        }


        String appWebInfPath = "/WEB-INF";
        //由于部署方式變更為jar部署,此處不可以使用改方式獲取路徑
//        ServletContext ctx = cfg.getServletContext();
//        String realWebInfPath = ctx.getRealPath(appWebInfPath);

        FileProvider config = null;
        String realWebInfPath = EngineConfigurationFactoryServlet.class.getResource(appWebInfPath).getPath();

   
        InputStream iss = ClassUtils.getResourceAsStream(EngineConfigurationFactoryServlet.class, appWebInfPath + "/" + SERVER_CONFIG_FILE);
        if (iss != null) {
            config = new FileProvider(iss);
        }

        if (config == null) {
            log.error(Messages.getMessage("servletEngineWebInfError03", ""));
        }

        if (config == null && realWebInfPath != null) {
            try {
                config = new FileProvider(realWebInfPath, configFile);
            } catch (ConfigurationException e) {
                log.error(Messages.getMessage("servletEngineWebInfError00"), e);
            }
        }

        if (config == null) {
            log.warn(Messages.getMessage("servletEngineWebInfWarn00"));
            try {
                InputStream is =
                        ClassUtils.getResourceAsStream(AxisServer.class,
                                SERVER_CONFIG_FILE);
                config = new FileProvider(is);

            } catch (Exception e) {
                log.error(Messages.getMessage("servletEngineWebInfError02"), e);
            }
        }

        return config;
    }
}

有兩點需要注意:

  1. 這個配置類必須放在org.apache.axis.configuration包下,否則不生效,別問為什么,我也不知道...
  2. 代碼中48行左右,String appWebInfPath = "/WEB-INF";指向的文件夾就是一開始創(chuàng)建的 WEB-INF

最后一步

在啟動類加上注解 @ServletComponentScan

@SpringBootApplication
@ServletComponentScan
public class TestApplication {
    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }
}

啟動程序,訪問 http://localhost:8080/axis-services,會顯示已發(fā)布的 WebService 接口信息,示例接口地址為:http://localhost:8080/axis-services/DemoService?wsdl。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 接口
    +關(guān)注

    關(guān)注

    33

    文章

    8257

    瀏覽量

    149950
  • 文件
    +關(guān)注

    關(guān)注

    1

    文章

    551

    瀏覽量

    24559
  • spring
    +關(guān)注

    關(guān)注

    0

    文章

    335

    瀏覽量

    14259
  • 服務(wù)端
    +關(guān)注

    關(guān)注

    0

    文章

    66

    瀏覽量

    6947
  • SpringBoot
    +關(guān)注

    關(guān)注

    0

    文章

    172

    瀏覽量

    145
收藏 人收藏

    評論

    相關(guān)推薦

    工程從CCS5.1遷移到CCS5.3下有什么注意事項

    如題,想請教一下專家,應(yīng)用工程之前在CCS5.1開發(fā)的,編譯器版本為7.3.1,bios版本為6.32.5.54,現(xiàn)在想將工程遷移到CCS5.3上,有什么注意事項?另外之前在CCS5.1下面
    發(fā)表于 06-21 08:29

    如何將Spartan 6遷移到Artix-7?

    我們有一個為XC6SLX25開發(fā)的設(shè)計,我們希望轉(zhuǎn)移到Artix-7以節(jié)省電力。我們可以通過將設(shè)計遷移到Artix-7來實際期望節(jié)省電力嗎?
    發(fā)表于 05-01 12:44

    EDK項目遷移到vivado的建議有哪些?

    大家好,我正在開發(fā)一個目前處于planAhead ISE的項目。我正在將該EDK項目遷移到vivado。當(dāng)我嘗試遷移IP時,我能夠成功遷移我的一些IP,我收到了帖子附帶的通知。請有人建
    發(fā)表于 05-06 10:31

    如何將CCSv3.3遷移到CCSv4?

    如何將CCSv3.3遷移到CCSv4
    發(fā)表于 02-25 07:15

    為什么KEIL4遷移到KEIL5的工程會發(fā)生報錯的問題呢

    為什么KEIL4遷移到KEIL5的工程會發(fā)生報錯的問題呢?如何去解決?
    發(fā)表于 12-20 07:49

    請問一下mysql怎么快速遷移到oceanBase?。?/a>

    mysql怎么快速遷移到oceanBase啊
    發(fā)表于 05-30 17:04

    請問如何從codeaurora遷移到github?

    我注意到最近恩智浦存儲庫從 codeaurora 轉(zhuǎn)移到了 github。我們?nèi)绾卧谌匀皇褂?BSP31 的同時更改它,因為我們目前沒有時間遷移到更新的 BSP 版本。在版本 31 的新 github repo 中,.xml 文件中仍然有 codeaurora 鏈接。
    發(fā)表于 04-07 06:35

    將codeaurora遷移到github后yocto構(gòu)建失敗了怎么解決?

    將 codeaurora 遷移到 github 后 yocto 構(gòu)建失敗
    發(fā)表于 04-21 08:12

    從電源架構(gòu)遷移到ARM的應(yīng)用說明

    本文檔的目的是強調(diào)那些參與將軟件應(yīng)用程序從Power架構(gòu)遷移到ARM平臺的人員感興趣的領(lǐng)域。 本文并不試圖將一種體系結(jié)構(gòu)提升到另一種體系結(jié)構(gòu)之上,只是為了清楚地解釋將現(xiàn)有軟件應(yīng)用程序從一種體系結(jié)構(gòu)
    發(fā)表于 08-22 06:09

    如何幫助企業(yè)更快更輕松地遷移到云中

    企業(yè)將業(yè)務(wù)遷移到云端并不容易,但可以安全有效地完成。企業(yè)對于業(yè)務(wù)速度的需求,需要更快地構(gòu)建的能力,這是遷移到AWS等公共云平臺的驅(qū)動因素之一。
    的頭像 發(fā)表于 09-28 02:42 ?2226次閱讀

    組織如何有效地將業(yè)務(wù)遷移到云平臺

    調(diào)研機構(gòu)Gartner公司指出,如果不采取正確的策略,組織遷移到云平臺將會導(dǎo)致成本增加、安全漏洞以及對云遷移結(jié)果的失望。
    的頭像 發(fā)表于 01-03 14:32 ?1981次閱讀

    如何將Hadoop遷移到云平臺中?

    希望實現(xiàn)數(shù)據(jù)基礎(chǔ)設(shè)施的現(xiàn)代化并將Hadoop遷移到云平臺中嗎?以下是組織在數(shù)據(jù)遷移之前需要問的五個問題:
    發(fā)表于 05-05 16:59 ?812次閱讀

    AN5426_STM32CubeMX 5_4_0的中間組件工程遷移到STM32CubeMX 5_5_0

    AN5426_STM32CubeMX 5_4_0的中間組件工程遷移到STM32CubeMX 5_5_0
    發(fā)表于 11-21 08:11 ?0次下載
    AN5426_STM32CubeMX 5_4_0的中間組件<b class='flag-5'>工程</b><b class='flag-5'>遷移到</b>STM32CubeMX 5_5_0

    如何將Keil μVision工程遷移到SEGEGR Embedded Studio?

    和GCC,也支持外部工具鏈,如Clang/LLVM、IAR或ARM/KEIL編譯器。我們以一個基于Keil μVision 5.32的項目為例,介紹如何將其遷移到SES 中。
    的頭像 發(fā)表于 01-13 11:24 ?1890次閱讀

    遷移到基于Arm STM32的MSPMO指南

    電子發(fā)燒友網(wǎng)站提供《從遷移到基于Arm STM32的MSPMO指南.pdf》資料免費下載
    發(fā)表于 09-07 11:17 ?0次下載
    從<b class='flag-5'>遷移到</b>基于Arm STM32的MSPMO指南