SOFA使用记录

SOFA,即可扩展开放式金融服务架构,相较于其他服务架构,SOFA由于其spring上下文的模块隔离模式,使得SOFA架构的各个模块都拥有独立的spring配置,在应用拆分时,可以将模块的spring配置一同拆分出去,只需将本地服务改为远程服务即可。

一、安装插件

在idea的 Manage repositories 中添加自定义地址 : http://ide.alipay.net/plugin/list,添加完毕后搜索sofa,安装插件。
重启后即可看到SOFA工程创建按钮,如下:
在这里插入图片描述

二、新建工程

在这里插入图片描述
创建后的部分层级结构如下:
在这里插入图片描述

appname
|----app (应用目录)
|----|----test --测试层
|----|----web --视图展示层(配合SOFA MVC使用)
|----|----|----home --公共模块
|----|----biz --业务层
|----|----|----shared --公共模块
|----|----core
|----|----common
|----assembly (装配目录)
|----conf (SOFA 相关配置存放目录)
|----webroot (静态资源和 MVC 模块文件存放路径)
|----pom.xml (总POM文件)
在这里插入图片描述
如上图,每个模块都是有独立的spring.xml文件的。
各模块依赖关系
根据不同的sofa创建方式,工程结构还有以下类型:
在这里插入图片描述

文件生成后reimport一次pom.xml文件,然后添加启动入口,点击启动。
• IDEA 中:选择 File -> Open -> 选择工程根路径下的 pom.xml , 打开就可以了
• Eclipse 中:选择 File > Import > Existing Maven Projects,选择工程所在根目录,点击 “确定”。
有可能会报“Error running ‘xxxx’": Command line is too long…”的错,如果报错,就在.idea的workspace.xml文件中的PropertiesComponent中添加<property name="dynamic.classpath" value="true" />,如下图:
在这里插入图片描述

系统间服务调用

服务提供方

在 common-service-facade 中创建接口,biz-service-impl 中的实现类使用 @SofaService 注解注册为一个sofa服务,@ZonePublish(zoneType = {"XX"})注解指定服务中心,@SofaService 的 bindings 属性: bindings = @SofaServiceBinding(bindingType = "jvm") ,指定sofa服务是jvm类型的服务,bindingType = “tr” 、bindingType = “bolt” 则是暴露给其他系统。

服务调用方

1、jvm间服务调用,使用 @SofaReference 注解即可。
2、不同系统间调用,则要在 common-service-integration及一级菜单下 的pom中引入jar包,创建client类,在client类中使用 @SofaReference(interfaceType = XX.class, binding = @SofaReferenceBinding(bindingType = "bolt")) 来注入sofa服务,或者使用spring配置文件
<sofa:reference id="sofa接口名称" interface="sofa接口路径"> <sofa:binding.tr> <!--接口暴露类型--> <sofa:global-attrs test-url="服务地址" timeout="超时时间"/> <sofa:vip url="服务地址"/> </sofa:binding.tr> </sofa:reference>
待续……

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值