Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting BeanFactory not initialized or already closed when i try to get the bean from applicationContext
    primarykey
    data
    text
    <p>I am using JDKtimer(in spring project) to reload the bean method to refresh the meta data values. I have written following lines to fetch the bean. </p> <pre><code> Long schedulerDelayTime = AppParametersHelper.getLong(SCHEDULER_DELAY_TIME); Long schedulerRepeatTime = AppParametersHelper.getLong(SCHEDULER_REPEAT_TIME); ApplicationContext ctx = ApplicationContextUtil.getContext(); IPartyRequestDataCache partyRequestPingService = (IPartyRequestDataCache) ctx.getBean("partyRequestDataCache"); partyRequestPingService.refreshDataCache(); </code></pre> <p>and JDK timer is called in this way</p> <pre><code>TimerTask partyRequestSchedulertask = new DataCacheRefreshScheduler(); Timer timer = new Timer(); timer.schedule(partyRequestSchedulertask, schedulerDelayTime, schedulerRepeatTime); </code></pre> <p>I am getting following exception </p> <pre><code> Exception in thread "Timer-2" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'ref resh' before accessing beans via the ApplicationContext at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicat ionContext.java:171) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1045) at org.tiaa.partyrequest.listener.DataCacheRefreshScheduler.run(DataCacheRefreshScheduler.java:20) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) </code></pre> <p>after printing this error in console it is executing the refreshDataCache(). I can use try and catch block to capture this error but is there way to avoid this. why this is coming?</p> <p>There is another way to do JDK Timer using spring-servlet.xml file but here i can not pass the values for repeatInterval and startDelay from a file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload