Announcement Announcement Module
Collapse
No announcement yet.
Attributes, AOP and Timers don't seem to mix. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Attributes, AOP and Timers don't seem to mix.

    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:
    Code:
    	<bean id="deleteStaleSessionsTask" 
    		class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
    	    <property name="targetObject"><ref bean="sessionService"/></property>
    	    <property name="targetMethod"><value>deleteStaleSessions</value></property>
    	</bean>
    
    	<bean id="deleteStaleSessionsScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
    		<property name="delay">
    			<value>0</value>
    		</property>
    		<property name="period">
    			<value>100000</value>
    		</property>
    		<property name="timerTask">
    			<ref local="deleteStaleSessionsTask"/>
    		</property>
    	</bean>
    	
    	<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
    		<property name="scheduledTimerTasks">
    			<list>
    				<ref local="deleteStaleSessionsScheduledTask"/>
    			</list>
    		</property>
    	</bean>
    The exact exception message was:
    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:

    Code:
    	<bean id="deleteStaleSessionsTask" class="org.rhavyn.communities.services.core.impl.DeleteStaleSessionsTask"
    		autowire="byType"/>
    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.

    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.
Working...
X