English 中文(简体)
Wicket with Spring declarative transaction
原标题:

It is possible to use the Spring Framework s @Transactional support outside of a Spring container. In reference documentation is chapter about AspectJ aspect. I m trying to use it in my wicket application, but with no positive result.

application-context.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>

In my form class annotated by @Configurable, I have:

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

Stack trace:

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

You might be able to get this working using AspectJ load-time-weaving, but that s a very complex solution for a simple problem.

If you need declarative transactions, then I suggest you move the transactional logic from the wicket component down into a Spring bean, and invoke the Spring bean from the wicket object. The Spring bean would have the transactional annotations, and would be proxied correctly by the Spring container.

I have no experience with Wicket. But is your form class (the one that contains method annotated with @Transactional) Spring managed code? i.e. Who creates the instances of the class?

If it s not, that Spring will not provide @Transactional support (neither will @Autowired work, etc).





相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签