1.依赖的问题,升级到spring 2.x
<!-- Redis 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.1.6.RELEASE</version> </dependency> <!-- spring2.X集成redis所需common-pool2--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.6.2</version> </dependency>
2.配置
spring: redis: database: 1 host: 101.34.177.108 port: 6379 password: lPhx@FQvbRoQGCke timeout: 60000 lettuce: pool: max-active: 50 max-wait: -1 max-idle: 50 min-idle: 0
我是多线程操作
@Slf4j @Component public class ReplaceLazadaAttrTask { @Autowired private LazadaApiClient lazadaApiClient; @Qualifier("threadPoolTaskExecutor") @Autowired private ThreadPoolTaskExecutor poolTaskExecutor; //@Scheduled(cron = "0 8 4 * * THU" ) @Scheduled(cron = "0 15 11 * * FRI") public void toUpdateLazadaAttr() { log.info("定时更新lazada属性任务开始,开始执行时间:{}", LocalDateTime.now().toString()); List<String> siteList = new ArrayList<>(); siteList.add("SG"); siteList.add("MY"); siteList.add("VN"); siteList.add("TH"); siteList.add("PH"); siteList.add("ID"); siteList.forEach(s -> CompletableFuture.runAsync(() -> lazadaApiClient.toUpdateLazadaAttr(s),poolTaskExecutor)); log.info("定时更新lazada属性任务结束,结束执行时间:{}", LocalDateTime.now().toString()); } }