You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/08/25 01:36:32 UTC

[GitHub] [servicecomb-java-chassis] zhoudamin commented on issue #1646: HttpServerFilter过滤器怎么使用@Resource注入对象

zhoudamin commented on issue #1646:
URL: https://github.com/apache/servicecomb-java-chassis/issues/1646#issuecomment-679451102


   > HttpServerFilter 不是 bean, 因此不能注入 spring bean 对象。需要注入 spring bean 对象, 得采用 spring 的一些常用技巧, 在非 bean里面获取bean。
   > 
   > 比如可以自定义一个 bean:
   > 
   > ```
   > @Component("holder")
   > public class Holder{
   > @resource
   > private EncryptkeyInfo enKeyInfo;
   > @resource
   > private AuthUtil authUtil;
   > }
   > ```
   > 
   > 然后在 Filter里面通过 BeanUtils 获取 :
   > 
   > ```
   > Holder bean = BeanUtils.getBean("holder");
   > ```
   -----------------------------------------
   1、Holder 加个 Data 的lombok注解
   2、Holder bean = BeanUtils.getBean("holder");
   bean.getEncryptkeyInfo.getxxx
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org