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包缺失或冲突;

posted @ 2020-05-04 10:54  三七_37  阅读(3868)  评论(1编辑  收藏  举报