项目启动时报错Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
Posted 我们的问题主要是读书不多而想得太多
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目启动时报错Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError相关的知识,希望对你有一定的参考价值。
问题详细:
启动项目时,报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘searchIPAttributionService‘ defined in file [***\service\SearchIPAttributionService.class]:
Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1013) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:959) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5266) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5554) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1948) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1006) ... 33 more Caused by: java.lang.NullPointerException at ***.service.SearchIPAttributionService.load(SearchIPAttributionService.java:133) at ***.service.SearchIPAttributionService.load(SearchIPAttributionService.java:66) at ***.service.SearchIPAttributionService.<clinit>(SearchIPAttributionService.java:28) ... 40 more
解决过程:
1、检查配置,反反复复看了很多遍,确认没有问题。
2、 网上找了很多资料,类似的问题很多,看过答案以后依旧不得其要领。只好继续看报错代码,直到看到这一句:
Caused by: java.lang.NullPointerException at ***.service.SearchIPAttributionService.load(SearchIPAttributionService.java:133) at ***.service.SearchIPAttributionService.load(SearchIPAttributionService.java:66) at ***.service.SearchIPAttributionService.<clinit>(SearchIPAttributionService.java:28)
问题应该在本身的代码上,但是,我记得代码是测试过的,没有问题。但是,没有其他办法,只能顺着提示一步步寻找问题所在。最终,确实问题出在代码上。Spring在实例化这个类的时候,先执行静态方法时,某个类还未实例化,故而报了这个空指针错误。
经验教训:
1、解决问题,不要急躁,要淡定,淡定,淡定。
2、仔细看报错信息。
3、每次修改过代码以后,都要记得进行测试,确保修改是正确的。
以上是关于项目启动时报错Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError的主要内容,如果未能解决你的问题,请参考以下文章
spring注入时报错::No qualifying bean of type 'xxx.xxMapper'
开源项目运行时报错A problem was found with the configuration of task ‘:app:checkDebugManifest‘
vue项目编译时报错:FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory