這是由於Springboot Bean的加載機制所導致的,具體大家可以去研究源碼。
下面是我的解決方案,僅供參考。
A:
@Component
public class XxxConfig {
// 1
public static XxxConfig xxxConfig ;
@Resource
private RedisUtil redisUtil;
// 2
@PostConstruct
public void init() {
xxxConfig = this;
xxxConfig.redisUtil = this.redisUtil;
}
public boolean test() {
// 3.使用 jwtConfig.redisUtil 形式調用
return xxxConfig.redisUtil.set("abcd", "123456", 3600);
}
}