In my application I'm using commons-attribute driven declarative transactions with the DefaultAdvisorAutoProxyCreator. My applicationContext.xml is defined exactly the same way as the examples in the reference documentation. I got all of that up and running and it seemed to work fine. I'm using the ContextLoaderListener to load my ApplicationContext.
Now I'm trying to set up a timer which would clear stale data from a database table. What seems to be the simplest method to do this would be to use the MethodInvokingTimerTaskFactoryBean and have it invoke a clearStaleData method on one of my business objects. This business object has a class level DefaultTransactionAttribute assigned to it. When I start up my application, however, I end up with a FactoryBeanCircularReferenceException.
My timer setup looks like:
The exact exception message was:
<property name="targetObject"><ref bean="sessionService"/></property>
<bean id="deleteStaleSessionsScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
org.springframework.beans.factory.FactoryBeanCircu larReferenceException: Error creating bean with name 'deleteStaleSessionsTask': FactoryBean returned null object: not fully initialized due to circular bean reference
The sessionService is autowired by type and only has a single dependency, a dao. This dao is a subclass of HibernateDaoSupport. And, as I said previously, it has a class level DefaultTransactionAttribute.
I personally can't see where a circular bean reference could occur. But, since I couldn't get around it I thought I'd try making a new class which extends TimerTask and takes a sessionService as a parameter. The configuration changed to:
After configuring this, however, the declarative transaction management stopped working on sessionService. It doesn't even appear to evaluate the bean for declarative transaction management ... searching the log for "Candidate advice" shows that it isn't looking at that bean at all.
<bean id="deleteStaleSessionsTask" class="org.rhavyn.communities.services.core.impl.DeleteStaleSessionsTask"
The end result that I'd like a method on my service bean executed inside of a transaction when a timer fires. How it's configured is not important. I'm completely out of ideas on how to get it to work, though.
Thanks for any help.