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目录下

<?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: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"/>

</beans>

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

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

    @Resource
    AuthService authService;

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

GrailsApplication grailsApplication

AuthService authService;

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

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

 

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

转载于:https://my.oschina.net/xiachanzou/blog/879107

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值