普通springmvc项目转换为springboot项目

本文介绍了将一个基于Webservice的老系统改造成SpringBoot的过程。首先,阐述了改造的原因,接着详细描述了调整代码结构,创建新的SpringBoot模块,替换原有SpringMVC配置的步骤。涉及到的关键操作包括添加spring-boot-starter-web依赖,配置spring.factories,创建WebConfig以继承WebMvcConfigurerAdapter,设置错误页面,以及实现路由和服务的动态调度。最后提到了相关配置的动态打包部署和启动脚本。
摘要由CSDN通过智能技术生成

1.背景说明:近期要做一个支付网关系统,原来的网关系统买的别人的,用的技术比较老webservice,由于现在springboot比较火,关键是很好用,开箱即用,所以决定在原来系统的基础上进行改造。

2.开始动手:

原来的代码结构,如下图:



 

3.第一步,结构调整,先添加一个新的springboot模块:

从官网http://projects.spring.io/spring-boot/快速生成一个springboot示例,然后在主pom中添加一个新的module,命名为mag-spring-boot,我用的是idea,然后导入添加的模块。

新的项目代码结构图,去除了多余的模块,把相应的依赖进行整理:

 

 

4.代码配置以此替换,springmvc的配置替换。

web.xml的配置:

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">

	<display-name>mag-facade-web</display-name>

	<context-param>
		<param-name>logbackConfigLocation</param-name>
		<param-value>file:///opt/pay/config/basis/mag-tzt/mag-logback.xml</param-value>
	</context-param>
	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>com.netfinworks.mag</param-value>
	</context-param>
	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet>
	    <servlet-name>healthCheckDispatcher</servlet-name>
	    <servlet-class>com.netfinworks.common.monitor.web.servlet.HeathCheckDispatcherServlet</servlet-class>
	    <load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
	    <servlet-name>healthCheckDispatcher</servlet-name>
	    <url-pattern>/_health_check</url-pattern>
	</servlet-mapping>

	<!--param-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext.xml</param-value>
	</context-param>
	<!-- listener -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
	</listener>

    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

   dispatch-servlet的配置:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:util="http://www.springframework.org/schema/util"
	default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans"
	xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/util
	http://www.springframework.org/schema/util/spring-util.xsd
		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
		http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
	default-autowire="byName">

	<!-- 配置参数 -->
	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>file:///opt/pay/config/basis/mag-tzt/mag-app.properties</value>
				<value>file:///opt/pay/config/basis/mag-tzt/mag-sftp-config.properties
				</value>
			</list>
		</property>
	</bean>

	<!-- 收单网关 -->
	<bean name="/gateway/receiveOrder.do" class="com.netfinworks.mag.web.controller.RecvOrder">
		<property name="verifyService" ref="verifyService" />
		<!-- property name="notifyService" ref="notifyService" / -->
		<property name="contextUtil" ref="contextUtil" />
	</bean>
	
	<!-- 收单网关  投资通-->
	<bean name="/gateway/receiveOrderTzt.do" class="com.netfinworks.mag.web.controller.RecvOrderTzt">
		<property name="verifyService" ref="verifyService" />
		<property name="contextUtil" ref="contextUtil" />
	</bean>
	
	<bean name="/sdk_gateway/sdk_receiveOrder.do" class="com.netfinworks.mag.web.controller.SDKRecvOrder">
		<property name="verifyService" ref="verifyService" />
		<!-- property name="notifyService" ref="notifyService" / -->
		<property name="contextUtil" ref="contextUtil" />
	</bean>
	<!-- verifySign -->
	<bean name="verifyService" class="com.netfinworks.mag.web.verify.VerifyService">
		<property name="md5KeyService" ref="md5KeyService"></property>
		<property name="rsaService" ref="rsaService"></property>
		<property name="uesFacade" ref="uesFacade"></property>
	</bean>

	<bean name="md5KeyService" class="com.netfinworks.mag.web.sign.MD5KeyService">
	</bean>

	<bean name="rsaService" class="com.netfinworks.mag.web.sign.RSAService">
	</bean>

	<!-- ma -->
	<bean name="maQueryService" class="com.netfinworks.mag.ext.service.MaQueryService">
		<property name="memberFacade" ref="memberFacade" />
		<property name="accountFacade" ref="accountFacade" />
		<property name="merchantFacade" ref="merchantFacade" />
		<property name="bankAccountFacade" ref="bankAccountFacade" />
		<property name="udinghuoPartnerId" value="${udinghuo.partnerid}" />
		<property name="verifyFacade" ref="verifyFacade" />
	</bean>
	<!-- 鉴权系统 -->
	<jaxws:client id="authControlService"
		serviceClass="com.netfinworks.authsys.api.AuthControlService"
		address="${authsys.ws.url}/authControlFacadeAddress" />
	<!-- 鉴权相关 -->
	<bean name="authSysAuthControlService" class="com.netfinworks.mag.ext.service.AuthSysAuthControlService">
		<property name="authControlService" ref="authControlService" />
	</bean>
	<!--  cac卡账务中心-->
	<bean name="cacService" class="com.netfinworks.mag.ext.service.CacService">
		<property name="iBankAccountFacade" ref="iBankAccountFacade" />
	</bean>
	<jaxws:client id="iBankAccountFacade"
		serviceClass="com.netfinworks.cac.service.facade.IBankAccountFacade"
		address="${cac.ws.url}/BankAccountFacade" />
	<!-- ues -->
	<jaxws:client id="uesFacade"
		serviceClass="com.netfinworks.ues.services.UesRemoteService" address="${ma.ws.url}/UesRemoteService" />

	<!-- ma -->
	<jaxws:client id="memberFacade"
		serviceClass="com.netfinworks.ma.service.facade.IMemberFacade"
		address="${ma.ws.url}/MemberFacade" />

	<jaxws:client id="accountFacade"
		serviceClass="com.netfinworks.ma.service.facade.IAccountFacade"
		address="${ma.ws.url}/AccountFacade" />

	<jaxws:client id="merchantFacade"
		serviceClass="com.netfinworks.ma.service.facade.IMerchantFacade"
		address="${ma.ws.url}/MerchantFacade" />

	<jaxws:client id="bankAccountFacade"
		serviceClass="com.netfinworks.ma.service.facade.IBankAccountFacade"
		address="${ma.ws.url}/BankAccountFacade" />
		
	<jaxws:client id="verifyFacade"
		serviceClass="com.netfinworks.ma.service.facade.IVerifyFacade"
		address="${ma.ws.url}/VerifyFacade" />

	<!-- cashier -->
	<bean id="cashierQueryService" class="com.netfinworks.mag.ext.service.CashierQueryService">
		<property name="cashierFacade" ref="cashierFacade"></property>
	</bean>
	<jaxws:client id="cashierFacade"
		serviceClass="com.netfinworks.cashier.facade.api.CashierFacade"
		address="${cashier.ws.url}/cashierService">
	</jaxws:client>
	
	<!-- site -->
	<bean id="siteQueryService" class="com.netfinworks.mag.ext.service.SiteQueryService">
		<property name="siteFacade" ref="siteFacade"></property>
	</bean>	
	<jaxws:client id="siteFacade"
		serviceClass="com.netfinworks.site.facade.api.SiteFacade"
		address="${site.ws.url}/siteService">
	</jaxws:client>

	<!-- trade -->
	<bean id="tradeService" class="com.netfinworks.mag.ext.service.TradeService">
		<property name="tradeFacade" ref="tradeFacade"></property>
		<property name="cashierQueryService" ref="cashierQueryService"></property>
		<property name="maQueryService" ref="maQueryService"></property>
		<property name="netbankSuccessUrl" value="${netbank.success.url}"></property>
		<property name="whiteChannelCodeMap" value="${white.channel.code}"></property>
	</bean>
	<jaxws:client id="tradeFacade"
		serviceClass="com.netfinworks.tradeservice.facade.api.TradeProcessFacade"
		address="${trade.ws.url}/tradeProcessFacade">
	</jaxws:client>
	<http-conf:conduit name=".*/tradeProcessFacade">
		<http-conf:client ConnectionTimeout="25000"
			ReceiveTimeout="30000" />
	</http-conf:conduit>

	<!-- trade query -->
	<bean id="tradeQueryService" class="com.netfinworks.mag.ext.service.TradeQueryService">
		<property name="tradeQueryFacade" ref="tradeQueryFacade"></property>
	</bean>
	<jaxws:client id="tradeQueryFacade"
		serviceClass="com.netfinworks.tradeservice.facade.api.TradeQueryFacade"
		address="${trade.ws.url}/tradeQueryFacade">
	</jaxws:client>
	
	<!-- trade-site query -->
	<bean id="tradeSiteQueryService" class="com.netfinworks.mag.ext.service.TradeSiteQueryService">
		<property name="tradeSiteQueryFacade" ref="tradeSiteQueryFacade"></property>
	</bean>
	<jaxws:client id="tradeSiteQueryFacade"
		serviceClass="com.netfinworks.tradeservice.facade.api.TradeQueryFacade"
		address="${trade-query.ws.url}/tradeQueryFacade">
	</jaxws:client>
	
	<!-- acs -->
	<bean id="acsQueryService" class="com.netfinworks.mag.ext.service.AcsQueryService">
		<property name="authFacade" ref="authFacade"></property>
		<property name="merchantCofFacade" ref="merchantCofFacade"></property>
	</bean>
	<jaxws:client id="authFacade"
		serviceClass="com.netfinworks.acs.service.facade.ApiAuthorizationFacade"
		address="${acs.ws.url}/apiAuth" />
	<jaxws:client id="merchantCofFacade"
		serviceClass="com.netfinworks.acs.service.facade.MerchantConfigurationFacade"
		address="${acs.ws.url}/merchantCof" />
	<!-- 统一凭证 -->
	<bean id="voucherService" class="com.netfinworks.mag.ext.service.VoucherService">
		<property name="voucherFacade" ref="voucherFacade"></property>
	</bean>

	<jaxws:client id="voucherFacade"
		serviceClass="com.netfinworks.voucher.service.facade.VoucherFacade"
		address="${voucher.ws.url}/voucherFacade" />

	<!-- Fos -->
	<bean id="fosService" class="com.netfinworks.mag.ext.service.FosService">
		<property name="fosFacade" ref="fosFacade"></property>
		<property name="fundoutFacade" ref="fundoutFacade"></property>
		<property name="paymentFacade" ref="paymentFacade"></property>
	</bean>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值