spring - Getting BeanFactory not initialized or already closed when i try to get the bean from applicationContext -
i using jdktimer(in spring project) reload bean method refresh meta data values. have written following lines fetch bean.
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(); and jdk timer called in way
timertask partyrequestschedulertask = new datacacherefreshscheduler(); timer timer = new timer(); timer.schedule(partyrequestschedulertask, schedulerdelaytime, schedulerrepeattime); i getting following exception
exception in thread "timer-2" java.lang.illegalstateexception: beanfactory not initialized or closed - call 'ref resh' before accessing beans via applicationcontext @ org.springframework.context.support.abstractrefreshableapplicationcontext.getbeanfactory(abstractrefreshableapplicat ioncontext.java:171) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1045) @ org.tiaa.partyrequest.listener.datacacherefreshscheduler.run(datacacherefreshscheduler.java:20) @ java.util.timerthread.mainloop(timer.java:512) @ java.util.timerthread.run(timer.java:462) after printing error in console executing refreshdatacache(). can use try , catch block capture error there way avoid this. why coming?
there way jdk timer using spring-servlet.xml file here can not pass values repeatinterval , startdelay file.
try run code in @postcounstuct method, spring beans should initialized time.
Comments
Post a Comment