使用ClassPathXmlApplicationContext加载项目时,

  1. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/application.xml");
  2. context.start();

发生以下错误:

  1. java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
  2.  
  3. at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
  4. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
  5. at cn.lzj.service.UserServiceTest.testAdd(UserServiceTest.java:50)
  6. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  7. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  8. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  9. at java.lang.reflect.Method.invoke(Method.java:498)
  10. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
  11. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  12. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
  13. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  14. at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  15. at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
  16. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
  17. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
  18. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  19. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  20. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  21. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  22. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  23. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  24. at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  25. at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
  26. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
  27. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
  28. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
  29. 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问题的更多相关文章

  1. 解决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 ...

  2. 项目启动异常,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 ...

  3. 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 ...

  4. 【项目运行异常】BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking ...

  5. 报错 BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 的解决方法

    这个普遍是因为tomcat 的 jar包问题,重新导入一下tomcat的jar包就OK了.

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

    这个坑爹的玩意 有几个出现错误的原因 服务器 1.服务器重复启动同一个部署 这个时候要停止然后启动 电脑差的 重启电脑 重启服务器就好了 代码 2.bean工厂不知道哪里关闭 3.bean工厂没有找到 ...

  7. BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法

    今天在写Spring程序时遇到了一个很常见的错误,而我以前好像一直没碰到过,今天才见到这个错误,经过研究解决了这个错误,犯这个错误真是不应该啊. log4j:WARN No appenders cou ...

  8. BeanFactory not initialized or already closed - call 'refresh' before access

    错误:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' b ...

  9. eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo

    报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...

随机推荐

  1. HDFS超租约异常总结(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException)

    HDFS超租约异常总结(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) 转载 2014年02月22日 14:40:58 96 ...

  2. OpenJudge9278:旅行

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  131072kB 描述 转眼毕业了,曾经朝夕相处的同学们不得不都各奔东西,大家都去了不同的城市开始新的生活.在各自城 ...

  3. Operating System-进程间互斥的问题-生产者&&消费者引入

    之前介绍的几种解决进程间互斥的方案,不管是Peterson方案还是TSL指令的方式,都有一个特点:当一个进程被Block到临界区外面时,被Block的进程会一直处于忙等待的状态,这个不但浪费了CPU资 ...

  4. Salesforce注册教程

    打开网址 https://developer.salesforce.com/,点击右上角的Sign up(注册) 在页面输入基本信息 >Name:First(姓名) Last(姓)  >E ...

  5. 在<img src="..." title="..."> 中使title的内容换行的方法

    在<img src="..." title="...">中要使TITILE的内容换行,不能使用html标签,只能用ASCII码,方法如下: < ...

  6. IDEA 设置导出

    见附件 https://files.cnblogs.com/files/chuancheng/settings.7z

  7. Maven 创建动态web 3.0项目

    使用eclipse 创建Maven 项目时候 默认是2.3的,需要一些小技巧把他转换成3.0项目 操作步骤如下分四步, 1.创建一个simple maven project 2. 转换成web3.0项 ...

  8. Spring MVC配置详解(1)

    web.xml的配置 <!-- 配置前端控制器 前端控制器(DispatcherServlet)--> <servlet> <servlet-name>spring ...

  9. Oracle、SqlServer——临时表

    一.oracle 1.概述: oracle数据库的临时表的特点: 临时表默认保存在TEMP中: 表结构一直存在,直到删除:即创建一次,永久使用: 不支持主外键. 可以索引临时表和在临时表基础上建立视图 ...

  10. DAY15-HTTP协议简述

    HTTP协议 一.HTTP协议简介 超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式.协作式和超媒体信息系统的应用层协议.HTTP是万维网 ...