我尝试自动装配SessionFactory,但得到此错误:
APPLICATION FAILED TO START
***************************
Description:
Field bookRepository in com.test.app.BookService required a bean named 'entityManagerFactory' that could not be found.
这里我自动装配SessionFactory:
@Service
class TestClass{
@Autowired
lateinit var sessionFactory: SessionFactory
......
}
这是我的配置类:
@Configuration
class SpringConfig {
@Bean
fun sessionFactory(emf: EntityManagerFactory): HibernateJpaSessionFactoryBean {
val fact = HibernateJpaSessionFactoryBean()
fact.entityManagerFactory = emf
return fact
}
}
我试着这样做:
@Configuration
class SpringConfig {
@Bean
fun sessionFactory(): HibernateJpaSessionFactoryBean {
return HibernateJpaSessionFactoryBean()
}
}
我的application.yml:
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: datasource_url
password: password
username: username
hikari:
maximum-pool-size: 5
jpa:
properties:
hibernate:
jdbc:
batch_size: 20
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
Hibernate版本:5.4.1
Spring boot版本:2.0.0.M3