Solve java. lang. IllegalStateException: BeanFactory not initialized or already closed,

Source: Internet
Author: User

Solve java. lang. IllegalStateException: BeanFactory not initialized or already closed,

I encountered this problem when I was running someone else's SSH project today.

Severe: Exception sending context initialized event to listener instance of class org. springframework. web. context. contextLoaderListenerorg. springframework. beans. factory. beanDefinitionStoreException: Failed to read candidate component class: file [D: \ Program Files \ tomcat-8.5.14 \ webapps \ privilegedemo \ WEB-INF \ classes \ cn \ itcast \ oa \ base \ BaseAction. class]; nested exception is java. lang. illegalArgumentException at org. springframework. context. annotation. classPathScanningCandidateComponentProvider. findCandidateComponents (ClassPathScanningCandidateComponentProvider. java: 281) at org. springframework. context. annotation. classpathbeandefinition.pdf. doScan (classpathbeandefinitionmessages. java: 242) at org. springframework. context. annotation. componentScanBeanDefinitionParser. parse (ComponentScanBeanDefinitionParser. java: 84) at org. springframework. beans. factory. xml. namespaceHandlerSupport. parse (NamespaceHandlerSupport. java: 73) at org. springframework. beans. factory. xml. beanDefinitionParserDelegate. parseCustomElement (BeanDefinitionParserDelegate. java: 1435) at org. springframework. beans. factory. xml. beanDefinitionParserDelegate. parseCustomElement (BeanDefinitionParserDelegate. java: 1425) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. parseBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 184) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. doRegisterBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 140) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. registerBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 111) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. registerBeanDefinitions (XmlBeanDefinitionReader. java: 493) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. doLoadBeanDefinitions (XmlBeanDefinitionReader. java: 390) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 334) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 302) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 174) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 209) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 180) at org. springframework. web. context. support. xmlWebApplicationContext. loadBeanDefinitions (XmlWebApplicationContext. java: 125) at org. springframework. web. context. support. xmlWebApplicationContext. loadBeanDefinitions (XmlWebApplicationContext. java: 94) at org. springframework. context. support. abstractRefreshableApplicationContext. refreshBeanFactory (AbstractRefreshableApplicationContext. java: 131) at org. springframework. context. support. abstractApplicationContext. obtainFreshBeanFactory (AbstractApplicationContext. java: 537) at org. springframework. context. support. abstractApplicationContext. refresh (AbstractApplicationContext. java: 451) at org. springframework. web. context. contextLoader. configureAndRefreshWebApplicationContext (ContextLoader. java: 383) at org. springframework. web. context. contextLoader. initWebApplicationContext (ContextLoader. java: 283) at org. springframework. web. context. contextLoaderListener. contextInitialized (ContextLoaderListener. java: 112) at org. apache. catalina. core. standardContext. listenerStart (StandardContext. java: 4745) at org. apache. catalina. core. standardContext. startInternal (StandardContext. java: 5207) at org. apache. catalina. util. lifecycleBase. start (LifecycleBase. java: 150) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1419) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1409) at java. util. concurrent. futureTask. run (Unknown Source) at java. util. concurrent. threadPoolExecutor. runWorker (Unknown Source) at java. util. concurrent. threadPoolExecutor $ Worker. run (Unknown Source) at java. lang. thread. run (Unknown Source) Caused by: java. lang. illegalArgumentException at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. core. type. classreading. simpleMetadataReader. <init> (SimpleMetadataReader. java: 52) at org. springframework. core. type. classreading. simpleMetadataReaderFactory. getMetadataReader (SimpleMetadataReaderFactory. java: 80) at org. springframework. core. type. classreading. cachingMetadataReaderFactory. getMetadataReader (CachingMetadataReaderFactory. java: 101) at org. springframework. context. annotation. classPathScanningCandidateComponentProvider. findCandidateComponents (ClassPathScanningCandidateComponentProvider. java: 257 )... 32 more September 30 10:52:06 org. apache. catalina. core. serious StandardContext listenerStart: Exception sending context initialized event to listener instance of class cn. itcast. oa. web. listener. OAInitListenerorg. springframework. beans. factory. beanDefinitionStoreException: Failed to read candidate component class: file [D: \ Program Files \ tomcat-8.5.14 \ webapps \ privilegedemo \ WEB-INF \ classes \ cn \ itcast \ oa \ base \ BaseAction. class]; nested exception is java. lang. illegalArgumentException at org. springframework. context. annotation. classPathScanningCandidateComponentProvider. findCandidateComponents (ClassPathScanningCandidateComponentProvider. java: 281) at org. springframework. context. annotation. classpathbeandefinition.pdf. doScan (classpathbeandefinitionmessages. java: 242) at org. springframework. context. annotation. componentScanBeanDefinitionParser. parse (ComponentScanBeanDefinitionParser. java: 84) at org. springframework. beans. factory. xml. namespaceHandlerSupport. parse (NamespaceHandlerSupport. java: 73) at org. springframework. beans. factory. xml. beanDefinitionParserDelegate. parseCustomElement (BeanDefinitionParserDelegate. java: 1435) at org. springframework. beans. factory. xml. beanDefinitionParserDelegate. parseCustomElement (BeanDefinitionParserDelegate. java: 1425) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. parseBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 184) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. doRegisterBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 140) at org. springframework. beans. factory. xml. defaultBeanDefinitionDocumentReader. registerBeanDefinitions (DefaultBeanDefinitionDocumentReader. java: 111) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. registerBeanDefinitions (XmlBeanDefinitionReader. java: 493) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. doLoadBeanDefinitions (XmlBeanDefinitionReader. java: 390) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 334) at org. springframework. beans. factory. xml. xmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 302) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 174) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 209) at org. springframework. beans. factory. support. abstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 180) at org. springframework. web. context. support. xmlWebApplicationContext. loadBeanDefinitions (XmlWebApplicationContext. java: 125) at org. springframework. web. context. support. xmlWebApplicationContext. loadBeanDefinitions (XmlWebApplicationContext. java: 94) at org. springframework. context. support. abstractRefreshableApplicationContext. refreshBeanFactory (AbstractRefreshableApplicationContext. java: 131) at org. springframework. context. support. abstractApplicationContext. obtainFreshBeanFactory (AbstractApplicationContext. java: 537) at org. springframework. context. support. abstractApplicationContext. refresh (AbstractApplicationContext. java: 451) at org. springframework. web. context. contextLoader. configureAndRefreshWebApplicationContext (ContextLoader. java: 383) at org. springframework. web. context. contextLoader. initWebApplicationContext (ContextLoader. java: 283) at org. springframework. web. context. contextLoaderListener. contextInitialized (ContextLoaderListener. java: 112) at org. apache. catalina. core. standardContext. listenerStart (StandardContext. java: 4745) at org. apache. catalina. core. standardContext. startInternal (StandardContext. java: 5207) at org. apache. catalina. util. lifecycleBase. start (LifecycleBase. java: 150) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1419) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1409) at java. util. concurrent. futureTask. run (Unknown Source) at java. util. concurrent. threadPoolExecutor. runWorker (Unknown Source) at java. util. concurrent. threadPoolExecutor $ Worker. run (Unknown Source) at java. lang. thread. run (Unknown Source) Caused by: java. lang. illegalArgumentException at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. asm. classReader. <init> (Unknown Source) at org. springframework. core. type. classreading. simpleMetadataReader. <init> (SimpleMetadataReader. java: 52) at org. springframework. core. type. classreading. simpleMetadataReaderFactory. getMetadataReader (SimpleMetadataReaderFactory. java: 80) at org. springframework. core. type. classreading. cachingMetadataReaderFactory. getMetadataReader (CachingMetadataReaderFactory. java: 101) at org. springframework. context. annotation. classPathScanningCandidateComponentProvider. findCandidateComponents (ClassPathScanningCandidateComponentProvider. java: 257 )... 32 more September 30 10:52:06 org. apache. catalina. core. standardContext startInternal: One or more listeners failed to start. full details will be found in the appropriate container log file September 30, 10:52:06, 2017 org. apache. catalina. core. standardContext startInternal severe: Context [/privilegedemo] startup failed due to previous errors September 30, 2017 10:52:06 PM org. apache. catalina. core. applicationContext log information: Closing Spring root WebApplicationContext September 30 10:52:06 org. apache. catalina. core. standardContext listenerStop severe: Exception sending context destroyed event to listener instance of class org. springframework. web. context. contextLoaderListenerjava. lang. illegalStateException: BeanFactory not initialized or already closed-call 'refresh' before accessing beans via the ApplicationContext at org. springframework. context. support. abstractRefreshableApplicationContext. getBeanFactory (AbstractRefreshableApplicationContext. java: 172) at org. springframework. context. support. abstractApplicationContext. destroyBeans (AbstractApplicationContext. java: 1090) at org. springframework. context. support. abstractApplicationContext. doClose (AbstractApplicationContext. java: 1064) at org. springframework. context. support. abstractApplicationContext. close (AbstractApplicationContext. java: 1010) at org. springframework. web. context. contextLoader. closeWebApplicationContext (ContextLoader. java: 549) at org. springframework. web. context. contextLoaderListener. contextDestroyed (ContextLoaderListener. java: 143) at org. apache. catalina. core. standardContext. listenerStop (StandardContext. java: 4792) at org. apache. catalina. core. standardContext. stopInternal (StandardContext. java: 5429) at org. apache. catalina. util. lifecycleBase. stop (LifecycleBase. java: 226) at org. apache. catalina. util. lifecycleBase. start (LifecycleBase. java: 154) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1419) at org. apache. catalina. core. containerBase $ StartChild. call (ContainerBase. java: 1409) at java. util. concurrent. futureTask. run (Unknown Source) at java. util. concurrent. threadPoolExecutor. runWorker (Unknown Source) at java. util. concurrent. threadPoolExecutor $ Worker. run (Unknown Source) at java. lang. thread. run (Unknown Source)

This is because the project was originally using spring3.2, while my jdk is 1.8, spring3.2 is not compatible with jdk 1.8, so these problems are caused by upgrading the spring version to version 4 or above.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.