Grails3添加dubbo分布式框架

grails3以上没有了很多配置文件,导致配置时走了一些弯路

官方文档对这些提的也不是太多

1)在新建的grails3.x项目中,引入dubbo依赖

// log4j2 compile 'org.apache.logging.log4j:log4j-core:2.4.1' compile 'org.apache.logging.log4j:log4j-api:2.4.1' compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.4.1' compile ('com.alibaba:dubbo:2.5.3') { exclude(group:"org.springframework",module: 'spring') exclude(module: 'log4j') } compile ('org.apache.zookeeper:zookeeper:3.4.6') // https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient compile 'com.github.sgroschupf:zkclient:0.1'

如果不去除dubbo依赖的spring和log4j,后面会引入很多冲突

2)添加dubbo依赖,并将文件命名为resources.xml,放置在/co f/spring目录下

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"

<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="owlApps" />

<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://localhost:2181" />
<!--<dubbo:protocol name='dubbo' payload='16777216' />-->
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />

<!-- 声明需要暴露的服务接口 -->
<dubbo:reference interface="com.owl.service.AccountService"  id="accountService" check="false"/>

<!-- 声明需要暴露的服务接口 -->
<dubbo:reference interface="com.owl.service.AuthService"  id="authService" check="false"/>

<!-- 声明需要暴露的服务接口 -->
<dubbo:reference interface="com.owl.service.BMUserService"  id="userService" check="false"/>

3)controller层引用前,@Resources声明

class TestController { private static Logger logger = Logger.getLogger(this); GrailsApplication grailsApplication

@Resource
AuthService authService;

当然,如果真的不写,也没事。

GrailsApplication grailsApplication

AuthService authService;

我试了一下,除了第一次的时候提醒没有找到这个bean,加上后再去掉也没再次报错。

应该是本地缓存的原因导致的第一次失败。

虽然已经去除了dubbo的依赖,但还是有时候出现log4j冲突的问题。如果有人能解决或知晓原因还请告知,感激不尽

评论

暂无评论