作为此处问题的后续内容:Spring 2.0 Annotations and ant
我们能够让注释正常工作(@ Transaction ),并尝试手动编写事务代码。
在这两种情况下,我们都遇到了一些问题。这是一个appfuse 1.9.4项目,我们手动升级到更新的Hibernate项目。这是使用Spring2.0。
我想要做的是将整个web服务包装在一个数据库“事务”中,这样整个“调用”就是原子的。我知道做这件事的“最简单”的方法是@Transactional?
为此,我们在类中添加了:
import org.springframework.transaction.annotation.Transactional;然后,在方法(它是公共的)旁边,我们做了:
@Transactional (readOnly = false, rollbackFor=Exception.class)
public List processEmployees(List employees){
....
}在applicationContext-hibernate.xml中,我添加了:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>现在,当我启动Tomcat时,我得到了这个可爱的错误:
[Scheduler] 2011-08-22 12:57:03,032 ERROR [main] ContextLoader.initWebApplicationContext(205) | Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Line 153 in XML document from ServletContext resource [/WEB-INF/applicationContext-hibernate.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The prefix "tx" for element "tx:annotation-driven" is not bound.
Caused by:
org.xml.sax.SAXParseException: The prefix "tx" for element "tx:annotation-driven" is not bound.我们使用的是Spring2.0,但没有“配置”任何AOP。
有什么想法吗?
或者,我很乐意用Transaction.commit()来做这件事,但是走那条路由会抛出一条关于事务永远不会启动的消息。
谢谢!
发布于 2011-08-23 02:10:31
您没有在applicationContext-hibernate.xml中定义"tx" namespace。因此,XML解析器无法识别元素。
https://stackoverflow.com/questions/7151606
复制相似问题