首页 > 技术文章 > Spring定时器调用Hibernate方法无法获得SessionFactory的解决办法

heyesp 2017-11-10 10:08 原文

由于在Spring定时器中无法通过注解的方式获取bean,因此需要通过原生的方式获取。获取session的方式如下:
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
SessionFactory factory=wac.getBean(SessionFactory.class);
Session session=factory.openSession();

推荐阅读