package com.sys.service; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import com.cku.dao.CkuMatchLoggerMapper; import com.cku.model.CkuMatchLogger; public class CkuMatchLoggerUtil implements ApplicationContextAware{ private static ApplicationContext applicationContext; // Spring应用上下文环境 private static CkuMatchLoggerMapper ckuMatchLoggerMapper; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { CkuMatchLoggerUtil.applicationContext = applicationContext; CkuMatchLoggerUtil.ckuMatchLoggerMapper = CkuMatchLoggerUtil.getBean("ckuMatchLoggerMapper"); } public static ApplicationContext getApplicationContext() { return applicationContext; } @SuppressWarnings("unchecked") public static T getBean(String name) throws BeansException { return (T) applicationContext.getBean(name); } public static void saveLoggerToDB(CkuMatchLogger ckuMatchLogger){ ckuMatchLoggerMapper.insert(ckuMatchLogger); } }