refactor: 网关启动时配置rsa

This commit is contained in:
CaptainB 2022-10-10 17:56:36 +08:00 committed by 刘瑞斌
parent 80f88ebd32
commit 1e913b3793
1 changed files with 7 additions and 5 deletions

View File

@ -3,17 +3,19 @@ package io.metersphere.gateway.config;
import io.metersphere.commons.utils.RsaKey; import io.metersphere.commons.utils.RsaKey;
import io.metersphere.commons.utils.RsaUtil; import io.metersphere.commons.utils.RsaUtil;
import io.metersphere.gateway.service.FileService; import io.metersphere.gateway.service.FileService;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.boot.ApplicationArguments;
import org.springframework.context.event.EventListener; import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource; import javax.annotation.Resource;
public class RsaConfig { @Configuration
public class RsaConfig implements ApplicationRunner {
@Resource @Resource
private FileService fileService; private FileService fileService;
@EventListener @Override
public void rsaKey(ContextRefreshedEvent event) throws Exception { public void run(ApplicationArguments args) throws Exception {
RsaKey value = fileService.checkRsaKey(); RsaKey value = fileService.checkRsaKey();
// 保存到缓存中 // 保存到缓存中
RsaUtil.setRsaKey(value); RsaUtil.setRsaKey(value);