You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure this is a bug or by-design because I found issue(#9150 , #9736) and pull request #9187 around, so I just post it here.
In Dubbo3.1.3, when using a setter method to auto-inject Spring bean into a custom Filter,the setter method is never invoked.
The Spring bean is actually a Properties,defined by @ConfigurationProperties(prefix = "codes"), which is registered as a bean with name <prefix>-<fqcn>. When Dubbo loads the filters, it will delegate the setter property to SpringExtensionInjector with the property(the bean name) from this code:
In SpringExtensionInjector, it only lookups a bean by type when the property is empty, under this circumstance, it will only lookup for a bean by name because the name of setter method is always like setXXX() instead of set(). Because the bean name registered into Spring is not the same as it gets from getSetterProperty method so the bean lookup will return null,which cause the setter method in filter never invoke.
private <T> T getOptionalBean(final ListableBeanFactory beanFactory, final String name, final Class<T> type) {
if (StringUtils.isEmpty(name)) {
return getOptionalBeanByType(beanFactory, type);
}
if (beanFactory.containsBean(name)) {
return beanFactory.getBean(name, type);
}
return null;
}
After I searched, the Spring-boot doesn't support specifying a bean name for @EnableConfigurationPropertiesspring-projects/spring-boot#19390.
Then I think the previous fix #9187 is option to fix it, by adding an annotation to the setter method and let the developer to decide how to inject. Or, by looking up the bean by type once failed to find bean by name in SpringExtensionInjector. Since this issue only happen under Spring-boot with @ConfigurationProperties, I prefer the latter.
I am not sure this is a bug or by-design because I found issue(#9150 , #9736) and pull request #9187 around, so I just post it here.
In Dubbo3.1.3, when using a setter method to auto-inject Spring bean into a custom Filter,the setter method is never invoked.
The Spring bean is actually a
Properties
,defined by@ConfigurationProperties(prefix = "codes")
, which is registered as a bean with name<prefix>-<fqcn>
. When Dubbo loads the filters, it will delegate the setter property toSpringExtensionInjector
with the property(the bean name) from this code:In
SpringExtensionInjector
, it only lookups a bean by type when the property is empty, under this circumstance, it will only lookup for a bean by name because the name of setter method is always likesetXXX()
instead ofset()
. Because the bean name registered into Spring is not the same as it gets fromgetSetterProperty
method so the bean lookup will returnnull
,which cause the setter method in filter never invoke.So I wonder:
The text was updated successfully, but these errors were encountered: