Spring学习中使用javaConfig进行配置时出现 has not been refreshed yet错误

java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@3caeaf62 has not been refreshed yetat org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1141)at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1159)at Test.test1(Test.java:11)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:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

原因是在Test类中ApplicationContext context = new AnnotationConfigApplicationContext();中忘记添加配置类对象。

即ApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class);

Spring学习中使用javaConfig进行配置时出现 has not been refreshed yet错误相关推荐

  1. Spring Boot中的application.properties配置简介(二)

    Spring Boot中的application.properties配置简介(二)   根据上文的介绍,我们已经对Spring Boot中的application.properties配置有了一定的 ...

  2. Spring Boot中的一些常用配置介绍!

    这篇教程将为你介绍Spring Boot 中的一些常用配置,比如:自定义 Banner.配置日志.关闭特定的自动配置等. 自定义Banner 在 Spring Boot 启动的时候会有一个默认的启动图 ...

  3. asp.net操作office时报错“检索 COM 类工厂中 CLSID 为 {...} 的组件时失败,原因是出现以下错误: 80070005。”

    在asp.net操作office组件时,会报错"检索 COM 类工厂中 CLSID 为 {...} 的组件时失败,原因是出现以下错误: 80070005.",由于office组件是 ...

  4. 检索 COM 类工厂中 CLSID 为 { } 的组件时失败,原因是呈现以下错误: 80040154

    检索 COM 类工厂中 CLSID 为 { } 的组件时失败,原因是呈现以下错误: 80040154 首先是要确认被调用com是否注册,如果没有注册,需要用管理员身份运行cmd, 进行 regsvr3 ...

  5. 徒手解密 Spring Boot 中的 Starter自动化配置黑魔法

    我们使用 Spring Boot,基本上都是沉醉在它 Stater 的方便之中.Starter 为我们带来了众多的自动化配置,有了这些自动化配置,我们可以不费吹灰之力就能搭建一个生产级开发环境,有的小 ...

  6. Spring Boot中使用MyBatis注解配置详解

    之前在Spring Boot中整合MyBatis时,采用了注解的配置方式,相信很多人还是比较喜欢这种优雅的方式的,也收到不少读者朋友的反馈和问题,主要集中于针对各种场景下注解如何使用,下面就对几种常见 ...

  7. webbrowser中localhost和发布的地址_004、Spring Boot中的项目属性配置

    我们知道,在项目中,很多时候需要用到一些配置的信息,这些信息可能在测试环境和生产环境下会有不同的配置,后面根据实际业务情况有可能还会做修改,针对这种情况,我们不能将这些配置在代码中写死,最好就是写到配 ...

  8. [转]在SSIS中,使用“包配置”时的常见错误与解析

    本文转自:http://www.cnblogs.com/invinboy/archive/2008/05/26/1034312.html 在以前的DTS中,在包的开发.测试.发布迁移过程中你必须手动的 ...

  9. Spring MVC中 log4j日志文件配置相对路径

    log4j和web.xml配置webAppRootKey 的问题 1 在web.xml配置 <context-param>   <param-name>webAppRootKe ...

最新文章

  1. 电影天堂React Native 客户端
  2. C#中三种定时器对象的比较
  3. 神经网络与机器学习 笔记—Rosenblatt感知机
  4. 何将ext中的FormPanel中,所有组件都居中放置?
  5. mysql 10分钟一聚合_SQL-根据DateTime查询多个聚合-MySQL
  6. 在windows文件系统中加右键执行程序
  7. alin39048错误原因_支付宝支付ALIN10146错误
  8. 概率论与数理统计 (二)计算题和应用题
  9. gif一键抠图 在线_不用下载的在线抠图软件哪里找?
  10. 2020年全国工业固体废物、危险废物产生量、利用处置量及防治措施分析[图]
  11. 谷歌邮箱lmap服务器填什么_解决Gmail的imap收发邮件无法连接服务器的问题
  12. 什么是北向接口和南向接口?
  13. R语言入门(1)时间序列分析
  14. PDF怎么拆分/合并? 3款 PDF 拆分和合并工具分享
  15. 手机突然电量消耗很快_手机电量消耗快是什么原因(手机电池电量突然猛掉)...
  16. [绝对值不等式] 货仓选址(绝对值不等式+贪心)
  17. 计算机辅助教学英语教案,谈英语计算机辅助教学
  18. 五大列级庄_详解五大名庄背后的1855分级
  19. 回溯法求解装载问题(DFS + 剪枝策略)
  20. 使用YOLOv5训练NEU-DET数据集

热门文章

  1. 网页设计(六)——基于HTML+CSS框架的网页设计实例
  2. Effective C++条款09:绝不在构造和析构过程中调用virtual函数
  3. 【吐血整理】2019年所有精品文章分类汇总!必收藏!
  4. R语言Bioconductor安装全流程
  5. 打车应用生死未卜 嘀嘀或傍上腾讯
  6. 中小学教师资格考试介绍
  7. 中国电子学会和nct哪个证书好,适合报名哪一个呢?
  8. 全网最流氓还擦边的App,被华为封杀了!
  9. java-接口之运动员教练员综合案例
  10. BIO NIO AIO 介绍与差别