Spring Boot 2.0.3 JDBC会话持久性错误

时间:2018-07-13 19:15:55

标签: java spring spring-boot

我有一个运行中的Spring Boot Web应用程序。我们想将会话持久化到数据库,因此我按照春季教程进行操作,发现here,并且在启动时遇到此错误:

Caused by: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'org.springframework.boot.autoconfigure.session.JdbcSessionConfiguration$SpringBootJdbcHttpSessionConfiguration': Unsatisfied dependency expressed through method 'setTransactionManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManager' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'connectionsConfiguration': Unsatisfied dependency expressed through field 'emFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: 
Error creating bean with name 'sessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?

这是我的connectionsConfiguration类:

@Configuration
public class ConnectionsConfiguration implements ApplicationListener<ApplicationReadyEvent> {


@Autowired
DataSource dataSource;
@Autowired
private EntityManagerFactory emFactory;

@Bean
public EntityManager getEntityManager() {
    return emFactory.createEntityManager();
}

@Bean
@Scope("prototype")
public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
    LocalSessionFactoryBean fact = new LocalSessionFactoryBean();
    fact.setAnnotatedPackages("com.xxx.persistence.model");
    fact.setPackagesToScan("com.xxx.persistence.model");
    fact.setDataSource(dataSource);
    return fact;
}
}

如何使它正常工作?我是否需要显式定义sessionFactory?我觉得春天会在幕后处理这个问题。

0 个答案:

没有答案