Spring定时器调用Hibernate方法无法获得SessionFactory的解决办法

由于在Spring定时器中无法通过注解的方式获取bean,因此需要通过原生的方式获取。获取session的方式如下:
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
SessionFactory factory=wac.getBean(SessionFactory.class);
Session session=factory.openSession();
posted @ 2017-11-10 10:08  heyesp  阅读(912)  评论(0编辑  收藏  举报