Spring的refresh()方法相關異常——call 'refresh' before...


使用Spring,新建ApplicationContext對象或者配置ApplicationContext.xml文件之后,常見一下幾種錯誤:

1.LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: ......

翻譯:LifecycleProcessor對象沒有初始化,在調用context的生命周期方法之前必須調用'refresh'方法。


2.BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

翻譯:BeanFactory對象沒有初始化或已經關閉了,使用ApplicationContext獲取Bean之前必須調用'refresh'方法。


3.ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: ......

翻譯:ApplicationEventMulticaster對象沒有初始化,在context廣播事件之前必須調用'refresh'方法。

 

導致這些錯誤的可能原因:

1. web.xml中沒有配置ContextLoaderListener監聽,
需要配置:

1 <listener>
2      <listener-class>
3          org.springframework.web.context.ContextLoaderListener
4     </listener-class>
5 </listener>        

2. 少 aopalliance.jar包;

3. tomcat問題,關閉tomcat,clean后,然后再重啟;

4. tomcat的JDK版本和工程的JDK版本不一致,spring版本不支持jdk的版本,檢查JDK配置;

5. applicationContext.xml 中 xml 格式不正確;

6. 引入的application的配置文件有問題,可能是id或者property重復;

7. xml配置文件的配置順序有問題;

8. spring版本過低,需要配置4.0以上的版本;

9. jar包缺失或沖突;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM