[apache/dubbo]spring配置文件中配置default-lazy-init="true"时dubbo扫描失效?

2017-11-08 619 views
3

当spring 配置文件中 设置default-lazy-init="true" 时,不管是注解配置方式还是xml配置文件方式都不起作用。。

回答

6

@li362692680 @Lazy@Service Bean 上增加这个注解也没有效果吗?

4

@chickenlj DubboBeanDefinitionParser 76-78行:

RootBeanDefinition beanDefinition = new RootBeanDefinition();
beanDefinition.setBeanClass(beanClass);
beanDefinition.setLazyInit(false);
1

@mercyblitz

只能是fasle么?

9

The problem seems to be unresolved?

4

Let me have a look

4

对于这个问题,我们需要考虑以下两个方面

  • XML 配置是否支持延迟初始化

    对于XML配置,我们需要考虑default-lazy-initinbeanslazy-initin指定的bean,如下所示:

    <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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd" default-lazy-init="true"> // default-lazy-init
    
      <dubbo:application name="application"/>
    
      <!-- service configuration -->
      <dubbo:service interface="org.apache.dubbo.config.spring.api.DemoService" ref="demoService"/>
        // lazy-init for the specified bean
      <bean id="demoService" class="org.apache.dubbo.config.spring.impl.DemoServiceImpl" lazy-init="true"/>
    
    </beans>

    如果bean被 引用,则无论是set还是dubbo:service都不能延迟初始化,因为不支持延迟初始化。default-lazy-initlazy-inittruedubbo:service

    DubboBeanDefinitionParser将解析所有 bean,例如dubbo:xxx.如果它们都不支持延迟初始化(没有lazy-init属性),这里似乎没有问题。

    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(beanClass);
    beanDefinition.setLazyInit(false); // There is no problem here, beause all of dubbo:xxx bean don't support lazy-init attribute

    我们可以讨论是否所有的dubbo:xxxbean都需要支持lazy-init属性

  • 注解配置是否支持延迟初始化

    我已经测试过惰性注释不支持,并且我已经解决了这个问题。参见#7981

9

@pinxiong 大佬您好,我在您提完#7981 后,发现如果在privoder实现类上加上@Lazy时,provider就不会暴露到注册中心去了#8770, 按您这里的描述,provider应该是不支持@Lazy的,只是consumer侧支持对吧? 目前看应该是下图中把provider加上了@Lazy,导致provider延迟加载,没有触发ServiceConfig的export方法,从而没有注册到注册中心去。 image

目前我的改法是,去掉service的@Lazy标记。 您看我的理解是对的么?