代码之家  ›  专栏  ›  技术社区  ›  mmaceachran

Spring Boot 2.0.3 JDBC会话持久性错误

  •  1
  • mmaceachran  · 技术社区  · 8 年前

    我有一个工作的Spring Boot Web应用程序。我们希望将会话持久化到DB,所以我遵循了spring教程 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?
    

    @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 回复  |  直到 8 年前