fix(): 解决Redis无法注入的问题

真的服了非得自己new这个assetCache,就不能使用SpringBoot给你创建好的
master
dongzeliang 2024-05-17 09:26:44 +08:00
parent 3469875469
commit 6fe5f9d07a
3 changed files with 19 additions and 16 deletions

View File

@ -26,11 +26,11 @@ public abstract class CacheAbs<K, V extends List<?>> implements Cache<K> {
// this.redisService = redisService; // this.redisService = redisService;
// } // }
@Autowired // @Autowired
public CacheAbs(RedisService redisService) { // public CacheAbs(RedisService redisService) {
// if (redisService==null) redisService = new RedisService(); //// if (redisService==null) redisService = new RedisService();
this.redisService = redisService; // this.redisService = redisService;
} // }
/** /**
* key * key

View File

@ -17,9 +17,9 @@ import java.util.List;
public class AssetCache extends CacheAbs<String, List<BasicConfigInfo>> { public class AssetCache extends CacheAbs<String, List<BasicConfigInfo>> {
public AssetCache(RedisService redisService) { // public AssetCache(RedisService redisService) {
super(redisService); // super(redisService);
} // }
@Override @Override
public String preKey() { public String preKey() {

View File

@ -25,11 +25,14 @@ public class EtlApplicationRunner implements ApplicationRunner {
@Autowired @Autowired
private BasicConfigInfoService basicConfigInfoService; private BasicConfigInfoService basicConfigInfoService;
// @Autowired
// private RedisService redisService;
@Autowired @Autowired
private RedisService redisService; private AssetCache assetCache ;
AssetCache assetCache = new AssetCache(redisService);
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
List<BasicConfigInfo> basicConfigInfos = basicConfigInfoService.selectBasicConfigInfoList(new BasicConfigInfo() {{ List<BasicConfigInfo> basicConfigInfos = basicConfigInfoService.selectBasicConfigInfoList(new BasicConfigInfo() {{
@ -40,11 +43,11 @@ public class EtlApplicationRunner implements ApplicationRunner {
@Scheduled(zone = "0 0/10 * * * ? *") @Scheduled(zone = "0 0/10 * * * ? *")
public void delay(){ public void delay(){
if (!redisService.hasKey(assetCache.preKey()+"basic")) try { // if (!redisService.hasKey(assetCache.preKey()+"basic")) try {
throw new ServletException("过期了"); // throw new ServletException("过期了");
} catch (ServletException e) { // } catch (ServletException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
redisService.expire(assetCache.preKey()+"basic",10, TimeUnit.MINUTES); // redisService.expire(assetCache.preKey()+"basic",10, TimeUnit.MINUTES);
} }
} }