When my app starts and I am using Quartz, I am seeing that a bean (and all the beans that are injected into it) are getting instated twice--even though I am specifically saying that it is a singleton in my applicationContext.xml. I have verified that this is happening by tracking the instantiations:
This is a problem because that bean is managing a cache of data and I want to clear that cache via Quartz daily. I also want to be able to clear it using Struts Actions.Code:private static int instances = 0; public CacheManagementService() { super(); instances++; log.info("CacheManagementService INSTATED Number: " + instances); }
Here are relevant snippets from applicationContext.xml:
All the other beans (and Actions) seem to be using the correct cacheManagementService bean. But Quartz is instating its own cacheManagementService bean at startup.Code:... <bean id="customerServiceRepDAO" parent="abstractDAO" class="com.snowball.vtv.dao.CustomerServiceRepDAO"/> ... <bean id="cacheManagementService" class="com.snowball.vtv.service.CacheManagementService" singleton="true"> <property name="listOfCachers"> <list> <ref local="customerServiceRepDAO" /> ... </list> </property> </bean> ... <bean id="customerServiceRepService" parent="abstractService" class="com.snowball.vtv.service.CustomerServiceRepService"/> ... <!-- Quartz Job: Cache Management Clear --> <bean id="cacheManagementClear-QuartzJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="cacheManagementService"/> <property name="targetMethod" value="clearAll"/> </bean> <bean id="cacheManagementClear-QuartzCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="cacheManagementClear-QuartzJobDetail"/> <!-- fire every day during lunch --> <property name="cronExpression" value="0 40 11 * * ?"/> </bean> <!-- Quartz Schedule --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> ... <ref bean="cacheManagementClear-QuartzCronTrigger"/> </list> </property> </bean> ... <bean name="/CacheManagement" class="com.snowball.vtv.action.admin.CacheManagementAction"> <property name="cacheManagementService" ref="cacheManagementService"/> </bean>
Is this correct behaviour? If not, does anyone have any suggestions?


Reply With Quote