You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/07/24 18:44:02 UTC

[GitHub] [dubbo] JavaCodeWking opened a new issue, #10362: 混合使用注解和XML配置导致出现两个application实例(Mixing annotations and XML configuration results in two instances of application)

JavaCodeWking opened a new issue, #10362:
URL: https://github.com/apache/dubbo/issues/10362

   ### Environment
   
   * Dubbo version: 2.7.16
   * Operating System version: Window 10
   * Java version: 1.8
   
   ### Steps to reproduce this issue
   我并没有使用3.0以上版本,因为和其他的组件兼容性还不够好(I didn't use version 3.0 or above because the compatibility with other components was not good enough)
   1. 我使用@EnableDubbo和@DubboReference注解注入我需要的Spring bean,dubbo的application 和registry信息使用XML 配置,并使用@ImportResource加载此XML配置(I inject Spring beans using @EnableDubbo and @DubboReference, the application and registry information is configured using XML, and I use @ImportResource to load this XML configuration)
   2. 在运行项目后出现此错误(I got this error after running the project):org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.dubbo.config.ApplicationConfig' available: expected single matching bean but found 2: demo-consumer,org.apache.dubbo.config.ApplicationConfig#0
   3. 出现了两个application实例(There are two application instances)
   
   我给出实现上述错误的案例代码配置(I give the configuration of the case code that achieves the above error:):
   
   `@EnableDubbo
   @SpringBootApplication
   @ImportResource(value = "classpath:spring/dubbo-demo-consumer.xml")
   public class ConsumerApplication {
   
   	public static void main(String[] args) {
   		SpringApplication.run(ConsumerApplication.class, args);
   	}
   }`
   
   `<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
          xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://dubbo.apache.org/schema/dubbo
          http://dubbo.apache.org/schema/dubbo/dubbo.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd">
       <context:property-placeholder/>
       <dubbo:application name="demo-consumer"/>
       <dubbo:registry address="127.0.0.1:2181"/>
   </beans>`
   
   `@RestController
   public class TestController {
       @DubboReference
       private DemoService demoService;
   }`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] chickenlj commented on issue #10362: 混合使用注解和XML配置导致出现两个application实例(Mixing annotations and XML configuration results in two instances of application)

Posted by GitBox <gi...@apache.org>.
chickenlj commented on issue #10362:
URL: https://github.com/apache/dubbo/issues/10362#issuecomment-1235010421

   > 我并没有使用3.0以上版本,因为和其他的组件兼容性还不够好(I didn't use version 3.0 or above because the compatibility with other components was not good enough)
   
   这个问题能具体描述一下吗?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] wangchengming666 commented on issue #10362: 混合使用注解和XML配置导致出现两个application实例(Mixing annotations and XML configuration results in two instances of application)

Posted by GitBox <gi...@apache.org>.
wangchengming666 commented on issue #10362:
URL: https://github.com/apache/dubbo/issues/10362#issuecomment-1197622818

   可以尝试一下dubbo.config.mode,具体的值可以参考一下这个


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liufeiyu1002 commented on issue #10362: 混合使用注解和XML配置导致出现两个application实例(Mixing annotations and XML configuration results in two instances of application)

Posted by GitBox <gi...@apache.org>.
liufeiyu1002 commented on issue #10362:
URL: https://github.com/apache/dubbo/issues/10362#issuecomment-1193605162

   1. @EnableDubbo 注解里默认会注入一个application, 你通过xml手动注入一个application 对象 导致容器中 会存在俩个application对象,且都没设置@Primary注解 导致从spring 中获取的时候不知道拿哪一个
   2. 如果要使用@EnableDubbo  注解 即不需要配置xml,如果想使用dubbo注解和 xml 结合 则 不适用@EnableDubbo注解,在dubboxml中配置 <dubbo:annotation/>标签来支持注解


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org