问题描述:
(1)javaWeb项目启动中,还没启动完成,在下面这个类加载另一个Bean类,
(2)通过getBean方法获取到该Bean,可以获取到,不为null
(3)但是,调用该Bean的方法insertSelective()方法,进不去该方法
解决方法:
项目启动时,延迟5秒即可,下面这个类等待5秒,等它调用的Bean加载完,就能调用了
public enum RfidRecordStorage { INSTANCE; private static Logger logger = Logger.getLogger(RfidRecordStorage.class); static { try { Thread.sleep(5000); } catch (InterruptedException e) { logger.error("启动工程时休眠RfidRecordStorage类失败!"); } } public synchronized int store(AppRfidPassRecord appRfidPassRecord) { AppRfidPassRecordService appRfidPassRecordService = (AppRfidPassRecordService) SpringContextUtils.getApplicationContext().getBean("appRfidPassRecordService"); int resultNum = 0; resultNum = appRfidPassRecordService.insertSelective(appRfidPassRecord); return resultNum; } }