java - 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 会在幕后处理这个问题。
解决方案
推荐阅读
- python - 如何为 python 3.6.8 安装 selenium
- airbrake - Airbrake 控制面板 - 更改部署标签颜色
- java - 是否可以从 JCuda 将数据发送到定义为 Union 的 GPU 内存?
- c# - 我有一个问题和一个错误。C# CS8180
- java - 每次我点击 Space 时,Libgdx 跳跃和碰撞方法都不起作用
- python - 在 PPT 占位符中适合图片
- php - 会话变量在每次页面重新加载时销毁
- angular - 在Angular 7中使用变量作为参数的ngx-translate
- javascript - 在表单验证中包含数字签名
- python - Glumpy错误'OSError:[WinError 126]找不到指定的模块'