Spring Boot中获取SessionFactory

以下配置基于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;

你可能感兴趣的:(Spring Boot中获取SessionFactory)