我有一个看起来像这样的bean:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="rgerg.gerger.gergwerg.gerger" />
<property name="hibernateProperties">
<props>
........
</props>
</property>
</bean>
在DAO类中@Autowired。然后我需要使用来自http://www.querydsl.com/的类HibernateQueryFactory
,但我不能只创建一个new HibernateQueryFactory()
,我必须为此创建一个bean,这样我就可以在同一个DAO类中自动装配它。问题是HibernateQueryFactory应该传递一个Session对象,而这个对象又由sessionFactory.getCurrentSession()
生成。我的HibernateQueryFactory bean看起来像这样:
<bean id="hibernateQueryFactory" class="com.querydsl.jpa.hibernate.HibernateQueryFactory">
<constructor-arg value="#{sessionFactory.getCurrentSession()}" />
</bean>
在我的DAO课程中,我同时宣布了这两种方式:
@Autowired
private SessionFactory sessionFactory;
@Autowired
private HibernateQueryFactory hibernateQueryFactory;
当我尝试启动服务器时出现此错误:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jiraIssueDBDAO': Unsatisfied dependency expressed through field 'hibernateQueryFactory'; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
任何人都可以帮我找出我做错了什么吗?非常感谢