dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

spring 配置文件中 配置default-lazy-init="true" 时 dubbo扫描不起作用??

Open li362692680 opened this issue 9 years ago • 7 comments

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

li362692680 avatar Nov 08 '17 07:11 li362692680

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

mercyblitz avatar Nov 13 '17 06:11 mercyblitz

@chickenlj DubboBeanDefinitionParser 76-78行:

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

mercyblitz avatar Nov 13 '17 14:11 mercyblitz

@mercyblitz

只能是fasle么?

li362692680 avatar Nov 14 '17 09:11 li362692680

The problem seems to be unresolved?

jianpeng957 avatar May 22 '20 04:05 jianpeng957

Let me have a look

pinxiong avatar May 28 '21 00:05 pinxiong

For this issue, there are two aspects we need to consider as follows

  • XML configuration supports lazy initialization or not

    For XML configuration, we need to consider default-lazy-init in beans and lazy-init in the specified bean, see them as below:

    <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>
    

    If the bean is referenced by dubbo:service , which cannot be lazy initialized no matter default-lazy-init or lazy-init sets true, because dubbo:service don't support lazy initialization.

    DubboBeanDefinitionParser will parse all beans like dubbo:xxx. There seems to be no problem here, if all of them don't support lazy initialization(there are no lazy-init attribute).

    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
    

We can dissucss if all of dubbo:xxx beans need to support lazy-init attribute

  • Annotation configuration supports lazy initialization or not

    I have tested that Lazy annotation don't support and I have fix this issue. see #7981

pinxiong avatar Jun 04 '21 07:06 pinxiong

For this issue, there are two aspects we need to consider as follows

  • XML configuration supports lazy initialization or not For XML configuration, we need to consider default-lazy-init in beans and lazy-init in the specified bean, see them as below:

    <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>
    

    If the bean is referenced by dubbo:service , which cannot be lazy initialized no matter default-lazy-init or lazy-init sets true, because dubbo:service don't support lazy initialization. DubboBeanDefinitionParser will parse all beans like dubbo:xxx. There seems to be no problem here, if all of them don't support lazy initialization(there are no lazy-init attribute).

    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
    

We can dissucss if all of dubbo:xxx beans need to support lazy-init attribute

  • Annotation configuration supports lazy initialization or not I have tested that Lazy annotation don't support and I have fix this issue. see fix: Support Lazy annotation #7981

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

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

changfubai avatar Sep 20 '21 04:09 changfubai