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属性中。
   
![image](https://user-images.githubusercontent.com/24600271/133183902-eba21ed2-68bc-42f5-b03f-63e6338daa45.png)
   但是,在随后SpringExtensionFactory的初始化过程中又会调用SpringExtension#initialize,此处会清空当前的上下文
   
![image](https://user-images.githubusercontent.com/24600271/133184182-a47d28c9-e4d0-4ed4-8ca9-91c0cceeb7f0.png)
   
由于此处启动的是消费端,后面没有再次设置上下文进SpringExtensionFactory的地方,因此会导致Filter中相关的SpringBean注入不进去,结果如下所示。
   
![image](https://user-images.githubusercontent.com/24600271/133184466-0e889569-1656-4639-889d-8afee06e267a.png)
   
   
   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(这只是暂时止血的方案,是否”优雅“有待讨论)
   
![image](https://user-images.githubusercontent.com/24600271/133185130-71fc974f-c370-43b9-89f1-f1b95b74578a.png)
   
   
   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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to