apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.07k stars 10.2k forks source link

apollo无法兼容dubbo-spring-boot-starter #1184

Closed BossYi closed 6 years ago

BossYi commented 6 years ago

版本是0.10.2,已经在application.properties中加入 apollo.bootstrap.enabled=true,也试过提高ApolloApplicationContextInitializer的加载顺序,都无法适配dubbo-spring-boot-starter,其他的配置都可以。 dubbo-spring-boot-starter的版本是0.1.0,希望能够回复一下!

nobodyiam commented 6 years ago

能否上传一个简化的sample项目重现该问题?

BossYi commented 6 years ago

@nobodyiam 我这有对apollo如何指定meta_server的地址做了定制化,无法上传源码,不好意思。只能把这个jar发给您,然后我上传一个配置的demo吧,你看怎么样?

BossYi commented 6 years ago

@nobodyiam 已经确认问题,在引入apollo之后,会将dubbo service和reference的加载延后,如果在dubbo加载完成之前,在其他被@Configuration注解的类中注入某个dubbo服务,将会是null,导致启动报错。

BossYi commented 6 years ago

在没有引入apollo之前是没有这个问题的。

nobodyiam commented 6 years ago

apollo做的只是注入配置,不会将dubbo service和reference的加载延后吧,要不还是给一个简单的demo吧,只要把代码部分传上来就可以,jar包不需要的。

BossYi commented 6 years ago

公司这里无法上传github,做了拦截,我晚点上传一个demo给您。

nobodyiam commented 6 years ago

@BossYi

我写了一个demo项目,dubbo-spring-boot-starter是可以和apollo一起工作的,示例代码请参考:https://github.com/ctripcorp/apollo-use-cases

我用的是dubbo-spring-boot-starter的0.2.0版本,不过应该和0.1.0版本一样的。

BossYi commented 6 years ago

@nobodyiam 谢谢您,这个和我写的一样,启动是没有问题的,但是在加入shiro之后,在shiro配置类中使用注解注入dubbo的服务就不行了,改用xml才行。 ps:在没有引入apollo之前都是正常的。

BossYi commented 6 years ago

@nobodyiam 实际上就是 @Configuration注解的类中, @Configuration public class A { @Bean public B getB(){ B b = new B(); } }

在B中@feference 某个服务的时候,就会是null,在没有引入apollo之前都是正常的。

nobodyiam commented 6 years ago

@BossYi B中reference的某个服务需要确保在bean初始化后再使用,比如放在@PostConstruct的方法里面

liliang8858 commented 6 years ago

没有使用 dubbo-spring-boot-starter
直接引用 dubbo 2.6.0 版本 这个问题

1528992118 commented 6 years ago

其实这种自己写个dubbo的starter启动包好了,不复杂的

slankka commented 6 years ago

我也遇到类似的问题:@Reference注解不支持Placeholder,我已经解决了。 如果使用https://github.com/alibaba/dubbo-spring-boot-starter 这个的POM依赖,版本是2.0:

<dependency>
        <groupId>com.alibaba.spring.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>2.0.0</version>
    </dependency>

这个Dubbo-starter 是个假Dubbo-starter(玩笑)。

改用 https://github.com/apache/incubator-dubbo-spring-boot-project 这个Dubbo-starter的版本是:

<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.2.0</version>
</dependency>

区别在于,2.0.0引用的Dubbo版本是2.6.0。后者0.2.0 引用的版本是2.6.2。 查看Dubbo源码可以发现,2.6.2才支持 注解的 Placeholder的解析。

然而我并不知道这两个dubbo-spring-boot-starter哪个是真官方。(笑) 可能是两拨人维护。 "假"Dubbo-starter 的全版本引用的都是2.6.0。

另外Dubbo的ReferenceAnnotationBeanPostProcessor 和 Apollo的 ApolloProcessor 的Order 都是 LOWEST_PRECEDENCE. 因此需要加上

apollo.bootstrap.enabled = true
apollo.bootstrap.namespaces = application //这一行必须加,尤其是namespace=dubbo等其他情况,注解里面的来不及

在我自己的项目中已经完成兼容。

nobodyiam commented 6 years ago

关于dubbo spring boot starter,可以参考 #1102 中的讨论,建议使用 incubator-dubbo-spring-boot-project,这个目前测试下来都是OK的,也是官方维护的版本。

case先关闭了,如还有问题,可以提供更多信息,或进群交流。

nanprivate commented 5 years ago

@BossYi

我写了一个demo项目,dubbo-spring-boot-starter是可以和apollo一起工作的,示例代码请参考:https://github.com/ctripcorp/apollo-use-cases

我用的是dubbo-spring-boot-starter的0.2.0版本,不过应该和0.1.0版本一样的。

我用0.1.0试了不行