首页 > 解决方案 > Spring Boot 2.0.3 JDBC 会话持久性错误

问题描述

我有一个工作的 Spring Boot Web 应用程序。我们想将会话持久化到数据库,所以我遵循了春季教程,在此处找到 ,我在启动时收到此错误:

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 吗?我的印象是 spring 会在幕后处理这个问题。

标签: javaspringspring-boot

解决方案


推荐阅读