注入bean
package cn.xiaojf; import cn.xiaojf.today.data.rdb.repository.RdbCommonRepositoryImpl; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean; @SpringBootApplication @EnableJpaRepositories(repositoryBaseClass = RdbCommonRepositoryImpl.class) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public HibernateJpaSessionFactoryBean sessionFactory() { return new HibernateJpaSessionFactoryBean(); } }
application.properties 中配置
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database=mysql
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
直接在代码中注入
@Autowired private SessionFactory sessionFactory;
http://www.cnblogs.com/xiaojf/p/6613595.html
实践下来 service 层必须加事务注解,否则报错