以下配置基于spring boot版本1.4.2.RELEASE。
1.application.properties中,添加:
spring.jpa.properties.hibernate.current_session_context_class = org.springframework.orm.hibernate5.SpringSessionContext
2.创建类SpringConfig.class
@Configuration
public class SpringConfig {
@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
return new HibernateJpaSessionFactoryBean();
}
}
3.注入SessionFactory
@Resource
private SessionFactory sessionFacotry;