Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义Filter中通过 setXX 的方式注入 bean 失败 #9656

Closed
1 task
lj-example opened this issue Feb 7, 2022 · 4 comments
Closed
1 task

自定义Filter中通过 setXX 的方式注入 bean 失败 #9656

lj-example opened this issue Feb 7, 2022 · 4 comments
Labels
type/bug Bugs to being fixed

Comments

@lj-example
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.8
  • Operating System version: mac
  • Java version: jdk8

Steps to reproduce this issue

  1. dubbo-spring-boot-starter 集成 spring-boot 2.4.13
  2. 自定义 Filter 中通过 set 的方式注入 springBean 会出现注入失败的情况
@Slf4j
@Configuration
@RequiredArgsConstructor
@Activate(order = Ordered.LOWEST_PRECEDENCE)
public class ProviderLogFilter implements Filter {


    private CrmProviderConfig providerConfig;

    public void setProviderConfig(CrmProviderConfig providerConfig) {
        this.providerConfig = providerConfig;
    }

}
  1. 在 2.7.3 版本没有问题,经过查阅代码发现在 BeanFactoryUtils 中
        // Issue : https://github.com/alibaba/spring-context-support/issues/20
        String[] allBeanNames = beanNamesForTypeIncludingAncestors(beanFactory, beanType, true, false);
       // 此处的返回的 beanNames 与实际的 beanName 不一致,导致 containsElement 判断失败,不会执行 set方法。
      // 实际的beanName 为 `providerConfig` ,通过如上方式获取的 beanName 为`spring.dubbo.provider-xxx.xxx.config.CrmProviderConfig`     

        List<T> beans = new ArrayList<T>(beanNames.length);

        for (String beanName : beanNames) {
            if (containsElement(allBeanNames, beanName)) {
                beans.add(beanFactory.getBean(beanName, beanType));
            }
        }

Pls. provide [GitHub address] to reproduce this issue.

Expected Behavior

不是很理解 if (containsElement(allBeanNames, beanName)) 判断的原因

@lj-example lj-example added the type/bug Bugs to being fixed label Feb 7, 2022
@lj-example
Copy link
Author

还有在 2.7.8 的版本如何关闭 系统自动注入的那个 ApplicationConfig 啊 自定义了之后,启动项目就会出现 Expected single matching of application, but found 2 instances, will randomly pick the first one.

@dy-only
Copy link

dy-only commented Feb 9, 2022

我这里使用最新版本 3.0.5 同样注入不进去。3.0.2可以,不知道是不是同一个原因。

@lj-example
Copy link
Author

可以考虑追踪下 如上的代码位置,在 2.7.3版本是直接 Application.getBean 来获取的,后面就换了种方式,如上的代码会导致判断Bean 失败。你看看是不是也是同样的问题。

@chickenlj
Copy link
Contributor

在最新的 3.0.6 版本开始,修复了类似注入问题,请确认是否已修复:#9636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

3 participants