Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dubbo2.7.5: Duplicate ServiceBean found #685

Closed
leapcat opened this issue Mar 26, 2020 · 1 comment
Closed

Dubbo2.7.5: Duplicate ServiceBean found #685

leapcat opened this issue Mar 26, 2020 · 1 comment
Assignees
Milestone

Comments

@leapcat
Copy link

leapcat commented Mar 26, 2020

DUBBO版本:2.7.5
问题描述:使用DUBBO-Samples中的org.apache.dubbo.spring.boot.demo.provider进行测试。一个接口有2个实现类,分别使用@service(group="")来暴露服务。启动时ConfigManger认为2个Service的id是一样的,从日志看确实都是"org.apache.dubbo.spring.boot.demo.consumer.DemoService"。日志请看下面。造成的后果是:注册中心(NACOS)中只有一个服务注册上去。此问题在2.7.3版本不存在,我比较了2个版本的ConfigManager,新版本增加了checkDuplicate功能。
尝试解决:(1)降低到2.7.3版本,问题解决;(2)继续2.7.5版本,使用@service(provider="s1"),来区别两个ServiceBean的ID,又报了其他的错误。 请帮忙解决一下。

用法:
`
@service(group="s1", version = "1.0.0")
public class DefaultDemoService implements DemoService {}

@service(group="s2", version = "1.0.0")
public class DefaultDemoService2 implements DemoService {}
`

日志:

`
2020-03-26 18:34:03.243 INFO 12596 --- [ main] b.f.a.ServiceAnnotationBeanPostProcessor : [DUBBO] The BeanDefinition[Root bean: class [org.apache.dubbo.config.spring.ServiceBean]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] of ServiceBean has been registered with name : ServiceBean:org.apache.dubbo.spring.boot.demo.consumer.DemoService:1.0.0:s1, dubbo version: 2.7.5, current host: ...
2020-03-26 18:34:03.246 INFO 12596 --- [ main] b.f.a.ServiceAnnotationBeanPostProcessor : [DUBBO] The BeanDefinition[Root bean: class [org.apache.dubbo.config.spring.ServiceBean]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] of ServiceBean has been registered with name : ServiceBean:org.apache.dubbo.spring.boot.demo.consumer.DemoService:1.0.0:s2, dubbo version: 2.7.5, current host: ...

2020-03-26 18:34:04.195 WARN 12596 --- [ main] o.a.dubbo.config.context.ConfigManager : [DUBBO] Duplicate ServiceBean found, there already has one default ServiceBean or more than two ServiceBeans have the same id, you can try to give each ServiceBean a different id : <dubbo:service beanName="ServiceBean:org.apache.dubbo.spring.boot.demo.consumer.DemoService:1.0.0:s2" exported="false" unexported="false" ref="org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService2@abf688e" prefix="dubbo.service.org.apache.dubbo.spring.boot.demo.consumer.DemoService" uniqueServiceName="s2/org.apache.dubbo.spring.boot.demo.consumer.DemoService:1.0.0" interface="org.apache.dubbo.spring.boot.demo.consumer.DemoService" dynamic="true" version="1.0.0" deprecated="false" group="s2" id="org.apache.dubbo.spring.boot.demo.consumer.DemoService" valid="true" />, dubbo version: 2.7.5, current host: ...
`

@mercyblitz mercyblitz self-assigned this Mar 31, 2020
@mercyblitz mercyblitz modified the milestones: 2.7.6, 2.7.7 Mar 31, 2020
@mercyblitz mercyblitz reopened this Apr 21, 2020
@yanghuabang
Copy link

这个问题是由于service引入了id,如果没有设置id,都为空的话,就会认为这是同一个实现类,从而无法注入,参考这位老哥的链接https://www.jianshu.com/p/fedc5f0ca47f,贴上他的解决方案@Component
public class UpdateBeanPostProcessors implements BeanPostProcessor {
@OverRide
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

    if(beanName.contains("ServiceBean")){
        //这里设置id,否则会造成同一个Service有多个group时,只能注入第一个service
        ServiceBean serviceBean  = (ServiceBean) bean;
        serviceBean.setId(beanName);
    }
    return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    return bean;
}

}
2.7.6实测有效

mercyblitz added a commit to mercyblitz/dubbo-spring-boot-project that referenced this issue May 28, 2020
mercyblitz added a commit that referenced this issue May 28, 2020
* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #685 : Dubbo2.7.5: Duplicate ServiceBean found
mercyblitz added a commit that referenced this issue Jun 2, 2020
* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #685 : Dubbo2.7.5: Duplicate ServiceBean found

* To fix the declaration of years
mercyblitz added a commit that referenced this issue Aug 3, 2020
* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #685 : Dubbo2.7.5: Duplicate ServiceBean found

* To fix the declaration of years

* Polish #733 : Upgrading the dependencies

* Polish #734 : [Samples] Upgrading the latest Service-Introspection features

* Polish #736 : Duplicate RegistryConfig found, there already has one default RegistryConfig or more than two RegistryConfigs have the same id

* Polish #734 : [Samples] Upgrading the latest Service-Introspection features

* Revert "Polish #734 : [Samples] Upgrading the latest Service-Introspection features"

This reverts commit 3e57fbe.

* Polish #736 : Duplicate RegistryConfig found, there already has one default RegistryConfig or more than two RegistryConfigs have the same id

* Polish #728 : When openfeign and dubbo coexist, DubboAutoConfiguration.primaryPropertyResolver configuration causes openfeign call to fail

* Polish #728 : Refactor

* Bugfix test-cases

* Bugfix build errors

* Bugfix test-cases

* Bugfix test-cases
mercyblitz added a commit that referenced this issue Aug 3, 2020
* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #718 : [Samples] Introducing the samples deployed the external Servlet container

* Polish #685 : Dubbo2.7.5: Duplicate ServiceBean found

* To fix the declaration of years

* Polish #733 : Upgrading the dependencies

* Polish #734 : [Samples] Upgrading the latest Service-Introspection features

* Polish #736 : Duplicate RegistryConfig found, there already has one default RegistryConfig or more than two RegistryConfigs have the same id

* Polish #734 : [Samples] Upgrading the latest Service-Introspection features

* Revert "Polish #734 : [Samples] Upgrading the latest Service-Introspection features"

This reverts commit 3e57fbe.

* Polish #736 : Duplicate RegistryConfig found, there already has one default RegistryConfig or more than two RegistryConfigs have the same id

* Polish #728 : When openfeign and dubbo coexist, DubboAutoConfiguration.primaryPropertyResolver configuration causes openfeign call to fail

* Polish #728 : Refactor

* Bugfix test-cases

* Bugfix build errors

* Bugfix test-cases

* Bugfix test-cases

* Revert "Revert "Polish #734 : [Samples] Upgrading the latest Service-Introspection features""

This reverts commit 1db06dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants