春季:尚未配置任何事务管理器 [英] Spring: No transaction manager has been configured
问题描述
一段时间以来,我一直在努力解决这个问题,但没有找到解决方案.希望任何人都能帮助我.
I've been wrestling with this problem for a while, and don't see a solution. Hope anyone can help me.
我配置了一个HibernateTransactionManager.但是,我在日志文件中看到以下消息:
I have a HibernateTransactionManager configured. However, I see the following message in the log file:
调试[http-8080-1] AnnotationTransactionAttributeSource.getTransactionAttribute(107)|添加具有属性[PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-nl.forestfields.picnic.domain.model.exception.IllegalCostException]的事务处理方法[cashIn]
DEBUG [http-8080-1] AnnotationTransactionAttributeSource.getTransactionAttribute(107) | Adding transactional method [cashIn] with attribute [PROPAGATION_REQUIRED, ISOLATION_DEFAULT, -nl.forestfields.picnic.domain.model.exception.IllegalCostException]
调试[http-8080-1] AnnotationTransactionAspect.createTransactionIfNecessary(267)|由于未配置任何事务管理器,因此跳过事务连接点[nl.forestfields.picnic.view.controller.ShoppingListController.cashIn]
DEBUG [http-8080-1] AnnotationTransactionAspect.createTransactionIfNecessary(267) | Skipping transactional joinpoint [nl.forestfields.picnic.view.controller.ShoppingListController.cashIn] because no transaction manager has been configured
此外,在发生异常的情况下,交易不会回滚.
Also, in case of an exception, the transaction isn't rolled back.
这是我的配置:
picnic-servlet.xml:
picnic-servlet.xml:
<beans>
<context:component-scan base-package="picnic" />
<context:annotation-config />
<tx:annotation-driven />
.
.
.
picic-context-db.xml:
picnic-context-db.xml:
<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" id="sessionFactory">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${hibernate.connection.driver_class}</value>
</property>
<property name="url">
<value>${hibernate.connection.url}</value>
</property>
<property name="username">
<value>${hibernate.connection.username}</value>
</property>
<property name="password">
<value>${hibernate.connection.password}</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
应在事务内执行的代码:
The code that should be executed inside a transaction:
@Transactional(rollbackFor=IllegalCostException.class)
public ModelAndView cashIn(@RequestParam final Long id) throws IllegalCostException, llegalOrderStateException, IllegalShoppingListStateException {
final ShoppingList shoppingList = shoppingListRepository.getById(id);
shoppingList.cashIn();
shoppingListRepository.add(shoppingList);
return new ModelAndView(...);
}
任何人都可以看到问题吗?
Can anyone see the problem?
干杯, 吉普
推荐答案
尝试更改
<tx:annotation-driven />
to
<tx:annotation-driven transaction-manager="transactionManager" />
在这里找不到其他任何问题.
Couldn't find any other problem here.
这篇关于春季:尚未配置任何事务管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!