0

作为此处问题的后续: Spring 2.0 Annotations and ant

我们能够使注释正常工作(@Transactional),并且还尝试手动编写事务。

在这两种情况下,我们都会遇到一些问题。这是一个 appfuse 1.9.4 项目,我们手动升级到更新的 Hibernate 项目。这是使用 Spring 2.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.

我们使用的是 Spring 2.0,但没有“配置”任何 AOP。

有任何想法吗?

或者,我很乐意使用 Transaction.commit() 来执行此操作,但走这条路线会引发有关事务从未启动的消息。

谢谢!

4

1 回答 1

2

没有在applicationContext-hibernate.xml. 因此 XML 解析器无法识别元素。

于 2011-08-22T18:10:30.730 回答