Autowired对象使用ThreadLocalTargetSource填充,不会为每个类填充。
创始人
2024-11-12 16:30:17
0

要使用ThreadLocalTargetSource填充Autowired对象,可以按照以下步骤进行操作:

  1. 创建一个自定义的ThreadLocalTargetSource类,继承ThreadLocalTargetSource类,并重写getTarget()方法:
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.aop.target.ThreadLocalTargetSource;

public class CustomThreadLocalTargetSource extends ThreadLocalTargetSource {

    @Override
    public Object getTarget() throws Exception {
        Object target = super.getTarget();
        // 在此处对target对象进行一些处理,例如进行属性赋值等操作
        return target;
    }
}
  1. 在Spring配置文件中配置自定义的ThreadLocalTargetSource bean:

    
    

  1. 在需要使用ThreadLocalTargetSource填充的类中,使用@Autowired注解注入对应的对象,并使用@Lazy注解延迟初始化:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;

public class YourClass {
    
    @Autowired
    @Lazy
    private YourAutowiredBean yourAutowiredBean;
    // ...

}

通过以上步骤,就可以使用ThreadLocalTargetSource对@Autowired对象进行填充。每次调用getTarget()方法时,会返回一个经过处理的目标对象。需要注意的是,@Lazy注解用于延迟初始化@Autowired对象,确保在真正使用时才进行填充。

相关内容

热门资讯

透视辅助"aapok... 透视辅助"aapoker怎么选牌"详细辅助插件教程(私人局有透视攻略)关于aapoker怎么选牌机制...
透视实锤"wepok... 透视实锤"wepoker私人局辅助挂"详细辅助透牌教程(可以下载游戏攻略);大神普及一款德州ai内幕...
透视ai"poker... 透视ai"pokermaster脚本"详细辅助软件教程(私人局辅助挂辅助);实战中需综合运用上述技巧...
透视ai"德州局hh... 透视ai"德州局hhpoker"详细辅助靠谱教程(手机版透视脚本神器);《WPK辅助透视》‌:支持手...
透视能赢"wepok... 透视能赢"wepoker透视脚本免费app"详细辅助技巧教程(透视脚本免费透明);人气非常高,ai更...
透视辅助"aapok... 透视辅助"aapoker插件"详细辅助教你攻略(俱乐部辅助方法)1、玩家可以在aapoker插件软件...
透视ai"wepok... 这是一款非常优秀的wepoker俱乐部辅助 ia辅助检测软件,能够让你了解到wepoker俱乐部辅助...
透视实锤"WePOk... 这是一款非常优秀的WePOker有没有透视方法 ia辅助检测软件,能够让你了解到WePOker有没有...
透视辅助"wepok... 透视辅助"wepoker辅助分析器"详细辅助2025新版教程(可以设置盖牌软件)1、玩家可以在wep...
透视透视挂"wepo... 这是一款非常优秀的wepoker免费透视脚本 ia辅助检测软件,能够让你了解到wepoker免费透视...