0

Spring コンテナーの外部で Spring Framework の @Transactional サポートを使用することができます。リファレンス ドキュメントには、AspectJ アスペクトに関する章があります。改札アプリケーションで使用しようとしていますが、肯定的な結果はありません。

アプリケーションコンテキスト.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.
4

2 に答える 2

4

AspectJ load-time-weavingを使用してこれを機能させることができるかもしれませんが、それは単純な問題に対する非常に複雑な解決策です。

宣言型トランザクションが必要な場合は、トランザクション ロジックを wicket コンポーネントから Spring Bean に移動し、Spring Bean を wicket オブジェクトから呼び出すことをお勧めします。Spring Bean にはトランザクション アノテーションがあり、Spring コンテナーによって正しくプロキシされます。

于 2010-01-12T22:43:42.663 に答える
0

私はウィケットの経験がありません。しかし、あなたの「フォームクラス」( で注釈が付けられたメソッドを含むクラス@Transactional)Spring管理コードですか?つまり、誰がクラスのインスタンスを作成しますか?

そうでない場合、その Spring は@Transactionalサポートを提供しません (どちらも機能しない@Autowiredなど)。

于 2010-01-12T22:44:26.077 に答える