Dubbo+SpringBoot项目,consumer模块学习笔记

项目共三个模块;

  1. service(Service层,提供服务给controller层调用,数据类型为BO
  2. integration(适配层,调用提供者提供的服务,导入jar包依赖,数据类型为TO(涉及数据传输,主要序列化
  3. main(Controller层,前端请求Controller,前端传递的数据类型为Request,转为BO作为Service层的参数

项目入口为main模块中的GatewayApplication.java,调用了treefinance-b2b-loangateway-main-spring.xml

package com.treefinance.b2b.loangateway.main.server;

import com.treefinance.springboot.sso.annotation.EnableLoanSsoAuth;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@ServletComponentScan
@ImportResource(value = {"spring/treefinance-b2b-loangateway-main-spring.xml"})
@EnableScheduling
//@EnableLoanSsoAuth

public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

}

treefinance-b2b-loangateway-main-spring.xml代码如下:

<?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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">

    <context:component-scan base-package="com.treefinance.b2b.loangateway.main"/>
    <context:property-placeholder location="classpath:/config/treefinance-b2b-loangateway-main.properties"
                                  ignore-unresolvable="true"/>
    <aop:aspectj-autoproxy/>

    <import resource="classpath*:spring/dashu-diamond-spring.xml"/>

    <import resource="classpath*:spring/treefinance-b2b-loangateway-biz-service-spring.xml"/>

    <import resource="classpath*:spring/treefinance-b2b-loangateway-main-dubbo-registry.xml"/>

</beans>

treefinance-b2b-loangateway-main-spring.xml功能如下

  • 扫描了com.treefinance.b2b.loangateway.main包,treefinance-b2b-loangateway-main.properties文件内容为空;
  • 导入service模块下spring/treefinance-b2b-loangateway-biz-service-spring.xml配置文件;classpath*(带*);
  • 导入自身模块下spring/treefinance-b2b-loangateway-main-dubbo-registry.xml配置文件;classpath*(带*);
  1. 自身模块下spring/treefinance-b2b-loangateway-main-dubbo-registry.xml中
    1. 配置了<dubbo:application name="treefinance-b2b-loangateway"/>(和项目名一致)
    2. 配置了<dubbo:registry address="${dubbo.registry.address}"/>(和注册中心中的provider地址一致)
    3. 导入了<import resource="classpath:/spring/treefinance-b2b-loangateway-common-dubbo-integration.xml"/>配置文件(integration层的文件,配置了<dubbo:reference interface = "com.treefinance.b2b.loan.debtorcenter.common.facade.loandebtor.interfaces.DebtorEnterpriseFacadeService" id="debtorEnterpriseFacadeService" check="false"/>,id的属性要与注册中心提供服务的id名一致)

  2. service模块下spring/treefinance-b2b-loangateway-biz-service-spring.xml

    1. 扫描"com.treefinance.b2b.loangateway.biz.service"包,property文件配置也为空

    2. 导入<import resource="classpath:/spring/treefinance-b2b-loangateway-common-integration-spring.xml"/>

      配置文件(intergration模块代码)

    3. 导入<import resource="classpath:/spring/treefinance-b2b-loangateway-common-utils-spring.xml"/>

      配置文件(Util模块代码,项目没怎么用到)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值