java - NullpointerException while accessing Spring Bean factory + tomcat 8 startup -
we migrated java 7 java 8 , tomcat 6 tomcat 8. before migration , getting below issue during deployment of our services , deployment fails , tomcat not start.
what crazy that, not happen , intermittent (occurs once in 3 or 4 deployments).
below stack trace see during deployment.
caused by: java.lang.nullpointerexception @ com.async.classb.createclassc(classb.java) @ com.async.classa.afterpropertiesset(classa.java) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1573) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1511)
existing code: in our code have singleton classa, injected singleton classb. , prototype classc used in classb.
in classa, have afterpropertiesset(), where-in getting instance of classb using applicationcontext.
in classb trying instance of classc using beanfactory.
exact code looks this.
public classa implements applicationcontextaware, initializingbean { private applicationcontext applicationcontext; public void afterpropertiesset() throws exception { classb classb = (classb)applicationcontext.getbean("classb"); registry.registerasynclistener(this); } public void setapplicationcontext(applicationcontext applicationcontext) throws beansexception { this.applicationcontext = applicationcontext; } } public classb implements lifecycle, disposablebean, beanfactoryaware { private asyncmessagelistener createclassc(classa classa) { logger.warn("bean factory value ... " + getbeanfactory()); classc classc = (classc) getbeanfactory().getbean("classc", classc.class); return classc; } public void setbeanfactory(beanfactory beanfactory) throws beansexception { this.beanfactory = beanfactory; } public start(){ // code } public stop(){ // code } public isrunning(){ // code } public destroy(){ // code } }
when added more loggers, saw beanfactory ggets null value intermittently , hence nullpointerexception.
i not springs, , did basic research. looks like there no code issue , still wonder why beanfactory getting null value.
we tried replacing beanfactory apllicationcontext still same issue.
any appreciated.
Comments
Post a Comment