BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法
今天在写Spring程序时遇到了一个很常见的错误,而我以前好像一直没碰到过,今天才见到这个错误,经过研究解决了这个错误,犯这个错误真是不应该啊。
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.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.getBean(AbstractApplicationContext.java:1097)
at com.pb.demo.Test.main(Test.java:12)
BeanFactory没有实例化或者已经关闭了,其实产生错误的原因很简单,在写:
ApplicationContext ctx = new ClassPathXmlApplicationContext();
时,没有指定配置文件,Spring实例化BeanFactory的时候是默认到classPath下面查找名为applicationContext.xml的文件的,但是呢,你又没有指定,所以出现了这个错误。
这就是错误的原因,在括号写上配置文件名就行了。
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
这样的话就不会出现这样的错误了。
BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法的更多相关文章
- 解决java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext这个问题
今天在运行别人的SSH项目时,遇到了这个问题 严重: Exception sending context initialized event to listener instance of class ...
- java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
spring的项目中有时候会报错:java.lang.IllegalStateException: BeanFactory not initialized or already closed - ca ...
- 【项目运行异常】BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking ...
- 解决java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext问题
使用ClassPathXmlApplicationContext加载项目时, ClassPathXmlApplicationContext context = new ClassPathXmlAppl ...
- 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...
- 报错 BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 的解决方法
这个普遍是因为tomcat 的 jar包问题,重新导入一下tomcat的jar包就OK了.
- BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
这个坑爹的玩意 有几个出现错误的原因 服务器 1.服务器重复启动同一个部署 这个时候要停止然后启动 电脑差的 重启电脑 重启服务器就好了 代码 2.bean工厂不知道哪里关闭 3.bean工厂没有找到 ...
- BeanFactory not initialized or already closed - call 'refresh' before access
错误:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' b ...
- 问题BeanFactory not initialized or already closed - call 'refresh' before access
问题BeanFactory not initialized or already closed - call 'refresh' before access 2016-08-23 14:22 8565 ...
随机推荐
- Fireasy新版本发布
1.5.40.42028 2015-2-4 ** Fireasy.Common 1.DynamicBuilder新增使用表达式SetCustomAttribute的重载方法 2.DateTimeEx ...
- unix/linux中图形界面那些事
我们知道unix/linux刚开始的时候是没有图形界面的,随着时代的发展,排版.制图.多媒体应用越来越普遍了,这些需求都需要用到图形界面(Graphical User Interface).为此,MI ...
- 模拟MessageBox
原文:<模拟MessageBox> Posted on 2014/01/07 ======================================================= ...
- ios auto layout demystified (二)
Constraints Constraint Types Layout constraints (NSLayoutConstraint class, public)—这些规则指定了view的几何学.他 ...
- 加快MySQL逻辑恢复速度的方法和参数总结
日常工作中经常会有需要从mysqldump导出的备份文件恢复数据库的情况,相比物理备份恢复这种方式在恢复时间上往往显得力不从心. 本文就总结了几个对于逻辑备份恢复有加速作用的参数和操作 注意:我们的大 ...
- Mount NAS Storage in Linux Overview 转载
Mount NAS Storage in Linux Overview Mounting your NAS Storage to a device that runs on a Linux-based ...
- Linux动态库的搜索路径
下面是目录结构: pengdl@localhost:~$ tree test/test/├── fun.c├── Fun.h└── t1 └── main.c 1 directory, 3 fi ...
- 反射动态创建不同的Processor
1. 定义抽象方法 public abstract class BaseProcesser { public abstract void GetCustomerReportCard ...
- mysql 输出当前月所有日期与对应的星期
其实可以用存储过程,但想用另一种方法实现: 首先创建一个辅助表,可以设置CREATE TABLE `t4` ( `id` ) NOT NULL AUTO_INCREMENT, `num` ) DEFA ...
- MVC,如何在视图中声明方法,调用方法?
<div> <!--在视图中申明方法,此方法的类型已经固定为HelperResult--> @helper ShowHello(string s) { <div> ...