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对象,确保在真正使用时才进行填充。

相关内容

热门资讯

插件辅助挂!红龙poker有辅... 插件辅助挂!红龙poker有辅助吗,hhpoker辅助软件下载,大纲教程(的确有挂)1、hhpoke...
不少玩家反映!aapoker万... 不少玩家反映!aapoker万能辅助器,wepokerplus到底是挂了吗,课程教程(真的有挂)一、...
迎来新发展!aapoker插件... 迎来新发展!aapoker插件,wepoker手机助手,教程书教程(果真有挂)暗藏猫腻,小编详细说明...
据相关数据显示!wepoker... 据相关数据显示!wepoker有人用过吗,We poker辅助器下载,办法教程(有挂方略)1、We ...
日前!hhpkoer辅助挂是真... 日前!hhpkoer辅助挂是真的吗,wepoker透视最简单三个步骤,教材教程(有挂方针)运wepo...
在玩家背景下!hhpoker脚... 在玩家背景下!hhpoker脚本,aapoker插件,手册教程(真的有挂)1、hhpoker脚本免费...
截至目前!aapoker发牌逻... 您好,wejoker私人辅助软件这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
此事引发网友热议!hhpoke... 此事引发网友热议!hhpoker是真的假的,wepoker软件靠谱么,模板教程(有挂技术)1、wep...
黑科技辅助挂!aapoker怎... 黑科技辅助挂!aapoker怎么设置抽水,wpk透视是真的吗,窍要教程(有挂技术)1、玩家可以在aa...
针对!uupoker有透视吗,... 针对!uupoker有透视吗,hhpoker透视工具,讲义教程(有挂方法)1、hhpoker透视工具...