@Service
public class TokenOutOfDateHandler implements InitializingBean, ApplicationContextAware {
@Autowired
AdminService adminService;
@Autowired
AdminController adminController;
@Override
public void afterPropertiesSet() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
if (StringUtils.isEmpty(Global.TOKEN)) {
List<ImToken> token = adminService.getToken();
if (token.size() == 0) {
adminController.getToken();
} else {
Global.TOKEN = token.get(0).getAccess_token();
}
}
}
}
}).start();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
}
}
SpringBoot中自动运行的类
最新推荐文章于 2024-07-04 16:30:24 发布