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;
// }
@Autowired
public CacheAbs(RedisService redisService) {
// if (redisService==null) redisService = new RedisService();
this.redisService = redisService;
}
// @Autowired
// public CacheAbs(RedisService redisService) {
//// if (redisService==null) redisService = new RedisService();
// this.redisService = redisService;
// }
/**
* key

View File

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

View File

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