You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "NikoTung (via GitHub)" <gi...@apache.org> on 2023/04/12 07:23:26 UTC

[GitHub] [dubbo] NikoTung opened a new issue, #12078: Filter setter method not injected under Spring-boot environment

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

   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:
   
   ```
    private String getSetterProperty(Method method) {
           return method.getName().length() > 3 ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) : "";
       }
   ```
   
   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;
       }
   ```
   
   So I wonder:
   
   * Why this bean lookup process not compatible with prior to 3.0,because I found a fix on this https://github.com/apache/dubbo/pull/9187
   * The bean lookup process in Dubbo 3.x is by-design or just a bug?
   


-- 
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] AlbumenJ commented on issue #12078: Filter setter method not injected under Spring-boot environment

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #12078:
URL: https://github.com/apache/dubbo/issues/12078#issuecomment-1505185516

   This should be the expectation of the previous design. For this case, can you help to see how to fix it.


-- 
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] NikoTung commented on issue #12078: Filter setter method not injected under Spring-boot environment

Posted by "NikoTung (via GitHub)" <gi...@apache.org>.
NikoTung commented on issue #12078:
URL: https://github.com/apache/dubbo/issues/12078#issuecomment-1507805125

   After I searched, the Spring-boot doesn't support specifying a bean name for `@EnableConfigurationProperties` https://github.com/spring-projects/spring-boot/issues/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.


-- 
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] NikoTung commented on issue #12078: Filter setter method not injected under Spring-boot environment

Posted by "NikoTung (via GitHub)" <gi...@apache.org>.
NikoTung commented on issue #12078:
URL: https://github.com/apache/dubbo/issues/12078#issuecomment-1558574719

   Base on #12122 , this shouldn't be an issue, but I still hope there would be documents about it.
   
   > > Or it's not a good idea to inject Spring bean in Dubbo3 via a `setter` method?
   > 
   > It would be better to create a `Factory` class for yourself.


-- 
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] NikoTung closed issue #12078: Filter setter method not injected under Spring-boot environment

Posted by "NikoTung (via GitHub)" <gi...@apache.org>.
NikoTung closed issue #12078: Filter setter method not injected under Spring-boot environment
URL: https://github.com/apache/dubbo/issues/12078


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