You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/14 02:34:50 UTC
[GitHub] [dubbo] dkisser opened a new issue #8793: 3.0.1和3.0.2版本下Consumer端Filter注入SpringBean失败场景分析
dkisser opened a new issue #8793:
URL: https://github.com/apache/dubbo/issues/8793
- [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [ ] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
### Environment
* Dubbo version: 3.0.1、3.0.2
* Operating System version: Mac OS
* Java version: 1.8
### Steps to reproduce this issue
1. 编写一个Filter和一个普通SpringBean
2. 装载Filter
3. 启动dubbo-demo-annotation-consumer(dubbo内置示例工程)
Filter和SpringBean代码如下。
@Activate(group = {"consumer", "provider"})
public class DemoFilter implements Filter {
private DemoServiceComponent demoServiceComponent;
private ABTestBean abTestBean;
public void setDemoServiceComponent(DemoServiceComponent demoServiceComponent) {
this.demoServiceComponent = demoServiceComponent;
}
public void setAbTestBean(ABTestBean abTestBean) {
this.abTestBean = abTestBean;
}
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
System.out.println("1");
return invoker.invoke(invocation);
}
}
@Service("abTestBean")
public class ABTestBean {
private String name = "1f2";
}
启动后发现DemoFilter中的SpringBean无法注入。经分析,IOC启动是就会通过DubboInfraBeanRegisterPostProcessor##setApplicationContex将上下文设置进SprinExtensionFactory#CONTEXTS属性中。

但是,在随后SpringExtensionFactory的初始化过程中又会调用SpringExtension#initialize,此处会清空当前的上下文

由于此处启动的是消费端,后面没有再次设置上下文进SpringExtensionFactory的地方,因此会导致Filter中相关的SpringBean注入不进去,结果如下所示。

Pls. provide [GitHub address] to reproduce this issue.
### Expected Result
期望后续能有一个好的解决方案,目前提供两个止血方案。
1. 使用SpringContext自行获取,参考如下:https://blog.csdn.net/sinat_21184471/article/details/81353431
2. 在DubboBootstrapApplicationListener#onContextRefreshedEvent中将上下文加入到SpringExtensionFactory(这只是暂时止血的方案,是否”优雅“有待讨论)

What do you expected from the above steps?
### Actual Result
What actually happens?
If there is an exception, please attach the exception trace:
```
Just put your stack trace here!
```
--
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] chickenlj closed issue #8793: 3.0.1和3.0.2版本下Consumer端Filter注入SpringBean失败场景分析
Posted by GitBox <gi...@apache.org>.
chickenlj closed issue #8793:
URL: https://github.com/apache/dubbo/issues/8793
--
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] rainwolf01 commented on issue #8793: 3.0.1和3.0.2版本下Consumer端Filter注入SpringBean失败场景分析
Posted by GitBox <gi...@apache.org>.
rainwolf01 commented on issue #8793:
URL: https://github.com/apache/dubbo/issues/8793#issuecomment-1014679703
我也在3.0.5也遇到了~
--
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