方式1:实现ApplicationContextAware接口
步骤:
1.写一个工具类,实现ApplicationContextAware接口;
2.将此工具类在spring配置文件中配置;
3.在类中调用;
工具类代码:
public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext context;//声明一个静态变量保存
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext;
}
public static ApplicationContext getContext(){
return context;
}
}
配置applicationContext.xml文件
<bean id="springContextUtil" class="com.netsdk.util.SpringContextUtil"></bean>
使用
HashMap<String,String> map = new HashMap<>();
map.put("ID", UUID.randomUUID().toString());
map.put("ALARM_TIME",DateUtils.date2Str(DateUtils.datetimeFormat));
map.put("ALARM_TYPE","闯入告警");
ap.put("DEVICE_IP","192.168.0.98");
VideoMonitorService service = (VideoMonitorService) SpringContextUtil.getContext().getBean("videoMonitorService");
service.insertVideoAlarmInfo(map);
最新评论
大佬用了魔法还是用不了,无互联网访问
地址挂了
如果不用魔法是不是下载了也看不了
请问大佬能推荐渠道么 十分感恩