【问题标题】:Wicket with Spring declarative transaction带有 Spring 声明式事务的 Wicket
【发布时间】:2010-01-12 22:34:05
【问题描述】:

可以在 Spring 容器之外使用 Spring Framework 的 @Transactional 支持。在参考文档中是关于 AspectJ 方面的章节。我正在尝试在我的 wicket 应用程序中使用它,但没有积极的结果。

应用程序上下文.xml:

<tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" />
<context:annotation-config />
<context:component-scan base-package="com.wicket.app"/>
<context:spring-configured />

<bean id="annotationTransactionAspect" factory-method="aspectOf"
      class="org.springframework.transaction.aspectj.AnnotationTransactionAspect">
    <property name="transactionManager" ref="transactionManager"></property>
</bean>

在@Configurable 注释的表单类中,我有:

@Transactional
public void process(IFormSubmittingComponent submittingComponent) {
    super.process(submittingComponent);
    getDao().getEntityManager().flush();
}

堆栈跟踪:

org.apache.openjpa.persistence.TransactionRequiredException: Can only perform operation while a transaction is active.

【问题讨论】:

    标签: spring jpa transactions wicket aspectj


    【解决方案1】:

    也许可以使用 AspectJ load-time-weaving 来解决这个问题,但对于一个简单的问题,这是一个非常复杂的解决方案。

    如果您需要声明式事务,那么我建议您将事务逻辑从 wicket 组件下移到 Spring bean 中,并从 wicket 对象调用 Spring bean。 Spring bean 将具有事务性注释,并由 Spring 容器正确代理。

    【讨论】:

    • 是的,我的错。这个简单的解决方案更好。没有必要夸大其词。
    【解决方案2】:

    我没有使用 Wicket 的经验。但是您的“表单类”(包含用@Transactional 注释的方法)是Spring 托管代码吗?即谁创建了类的实例?

    如果不是,Spring 将不会提供 @Transactional 支持(@Autowired 也不会工作,等等)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    相关资源
    最近更新 更多