解决java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext问题
使用ClassPathXmlApplicationContext加载项目时,
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/application.xml");
context.start();
发生以下错误:
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:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at cn.lzj.service.UserServiceTest.testAdd(UserServiceTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
其实,就是因为参数中的配置文件在发布目录下没有。
这是可以这样解决:
1. 在构造函数的参数增加如下开头:
classpath:
2. 或者将配置文件发布到输出目录下
idea中输出目录在,更改File->Project Structure->Project Settings->Modules->项目名称->右侧的Paths->Compiler output

解决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' 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
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...
- 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 ...
- 报错 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 accessing beans解决办法
今天在写Spring程序时遇到了一个很常见的错误,而我以前好像一直没碰到过,今天才见到这个错误,经过研究解决了这个错误,犯这个错误真是不应该啊. log4j:WARN No appenders cou ...
- BeanFactory not initialized or already closed - call 'refresh' before access
错误:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' b ...
- eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo
报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...
随机推荐
- Python之用虚拟环境隔离项目,并重建依赖关系
下面将以安装django和mysqlclient介绍如何用虚拟环境隔离项目,并重建依赖关系.操作系统:windows 10:python版本:python3.7 1. 安装python虚拟环境 (1) ...
- 学习动态性能表(17)--v$segstat&v$segment_statistics
学习动态性能表 第17篇-(1)-V$SEGSTAT 2007.6.13 本视图实时监控段级(segment-level)统计项,支持oracle9ir2及更高版本 V$SEGSTAT中的常用列 T ...
- USB CDC & 可变形参
控制台的三种连接方式: 1.IP网络 2.USB 3.UART 一:介绍USB CDC方式: 1.控制台配置如下: 2.USB Product ID 可以是:0x0000/0x5300/0x0238 ...
- ABP 学习系列 - 目录
一.ABP 学习系列 - 入门介绍之单表 http://www.cnblogs.com/yabu007/p/8067694.html 二.ABP 学习系列 - 入门介绍之多表 http://www.c ...
- array_diff函数的注意事项
array_diff — 计算数组的差集 说明: array array_diff ( array $array1 , array $array2 [, array $... ] ) 对比返回在 ar ...
- [转] CentOS系统目录学习
最近初学Linux 对linux的目录产生了很多疑问,看到这篇文章,让我顿时对目录有了一个清晰的认识!推荐给大家! ------------------------------------------ ...
- Java-API-Package:java.math
ylbtech-Java-API-Package:java.math 1.返回顶部 1. Package java.math Provides classes for performing arbit ...
- 12-01Js表单验证和JsWindow
一.表单验证form 1.创建一个新的表单: <form id="id是唯一的,不可重复" name=“可重复”,method="post/get",ac ...
- xftp的简单使用
1.下载并安装Xftp工具.打开Xftp工具,点击“新建”. 2.在“新建会话属性”中选择“名称”为主机命名,在“主机”栏输入主机IP,“协议”和“端口号”使用sftp和22,在“用户名”和“密码“栏 ...
- DAY19-Pillow制作验证码
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...