一、异常描述
关于springframework启动初始化报"警告: Exception encountered during context initialization - cancelling refresh attempt..Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate ..Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE"错误异常,详情错误日志如下>>
十二月 17, 2018 11:25:42 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners@b@信息: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4b7b1, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1b7c680,@b@ org.springframework.test.context.support.DirtiesContextTestExecutionListener@48ff68]@b@十二月 17, 2018 11:25:42 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions@b@信息: Loading XML bean definitions from URL [file:/C:/xwood_net/project/other-project/HelloSpringMVC/target/classes/junitSpringContext.xml]@b@十二月 17, 2018 11:25:45 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh@b@信息: Refreshing org.springframework.context.support.GenericApplicationContext@9e4dc0: startup date [Mon Dec 17 23:25:45 CST 2018]; root of context hierarchy@b@十二月 17, 2018 11:25:46 下午 org.springframework.context.support.GenericApplicationContext refresh@b@警告: Exception encountered during context initialization - cancelling refresh attempt@b@org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpInvokerRequestExecutor' defined in file@b@ [C:\..rget\classes\com\xwood\springmvc\test\HttpInvokerRequestExecutor.class]: @b@ Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xwood.springmvc.test.HttpInvokerRequestExecutor]:@b@ Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1093)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1038)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)@b@ at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)@b@ at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)@b@ at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)@b@ at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)@b@ at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)@b@ at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)@b@ at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)@b@ at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)@b@ at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)@b@ at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)@b@ at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)@b@ at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)@b@ at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:252)@b@ at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:254)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)@b@ at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)@b@ at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)@b@ at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)@b@ at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)@b@ at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)@b@ at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)@b@ at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)@b@ at org.junit.runners.ParentRunner.run(ParentRunner.java:363)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@ at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@ at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xwood.springmvc.test.HttpInvokerRequestExecutor]:@b@ Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE@b@@b@ at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)@b@ at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1086)@b@ ... 41 more@b@Caused by: java.lang.NoSuchFieldError: INSTANCE@b@ at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)@b@ at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)@b@ at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)@b@ at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)@b@ at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)@b@ at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)@b@ at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)@b@ at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)@b@ at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)@b@ at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)@b@ at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:103)@b@ at com.xwood.springmvc.test.HttpInvokerRequestExecutor.<init>(HttpInvokerRequestExecutor.java:43)@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)@b@ at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)@b@ at java.lang.reflect.Constructor.newInstance(Constructor.java:526)@b@ at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)@b@ ... 43 more
二、解决方法
因项目引入httpcore-4.2.2.jar包和现有的library的依赖包发生冲突造成的,删除httpcore-4.2.2.jar包,即可解决问题了,如下图操作所示。