spring 配置文件中 配置default-lazy-init="true" 时 dubbo扫描不起作用??
当spring 配置文件中 设置default-lazy-init="true" 时,不管是注解配置方式还是xml配置文件方式都不起作用。。
@li362692680
@Lazy 在@Service Bean 上增加这个注解也没有效果吗?
@chickenlj DubboBeanDefinitionParser 76-78行:
RootBeanDefinition beanDefinition = new RootBeanDefinition();
beanDefinition.setBeanClass(beanClass);
beanDefinition.setLazyInit(false);
@mercyblitz
只能是fasle么?
The problem seems to be unresolved?
Let me have a look
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-initinbeansandlazy-initin the specifiedbean, 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
beanis referenced bydubbo:service, which cannot be lazy initialized no matterdefault-lazy-initorlazy-initsetstrue, becausedubbo:servicedon't support lazy initialization.DubboBeanDefinitionParserwill parse all beans likedubbo:xxx. There seems to be no problem here, if all of them don't support lazy initialization(there are nolazy-initattribute).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
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-initinbeansandlazy-initin the specifiedbean, 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
beanis referenced bydubbo:service, which cannot be lazy initialized no matterdefault-lazy-initorlazy-initsetstrue, becausedubbo:servicedon't support lazy initialization.DubboBeanDefinitionParserwill parse all beans likedubbo:xxx. There seems to be no problem here, if all of them don't support lazy initialization(there are nolazy-initattribute).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 attributeWe can dissucss if all of
dubbo:xxxbeans need to supportlazy-initattribute
- 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方法,从而没有注册到注册中心去。

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