Java.lang.IllegalStateException

1.启动项目没问题

2.使用Springboot的test类Debug的时候报错

java.lang.IllegalStateException: The ApplicationContext loaded for [[MergedContextConfiguration@1a75e76a testClass = CheckSystemChangeApplicationTests, locations = '{}', classes = '{class com.deltaww.CheckSystemChangeApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7c729a55, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5af3afd9, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6572421, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@dd8ba08, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@131774fe, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@768debd], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. This may be due to one of the following reasons: 1) the context was closed programmatically by user code; 2) the context was closed during parallel test execution either according to @DirtiesContext semantics or due to automatic eviction from the ContextCache due to a maximum cache size policy.at org.springframework.util.Assert.state(Assert.java:97)at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:128)at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:43)at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:350)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:355)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$7(ClassBasedTestDescriptor.java:350)at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:349)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$4(ClassBasedTestDescriptor.java:270)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:269)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:259)at java.util.Optional.orElseGet(Optional.java:267)at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:258)at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:101)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:100)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:65)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:111)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:111)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:79)at java.util.ArrayList.forEach(ArrayList.java:1257)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)at java.util.ArrayList.forEach(ArrayList.java:1257)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

最后发现是程序中使用了ConfigurableApplicationContext

@Component
public class MyRunner implements ApplicationRunner {@Autowiredprivate CheckDataController checkDataController;@Autowiredprivate ConfigurableApplicationContext context;@Overridepublic void run(ApplicationArguments args) throws Exception {checkDataController.checkDataChange();System.out.println("automatically turn off tomcat");context.close();}
}

所以,debug的时候把这行注释掉

// context.close();    注掉

是不是无语的很,Tomcat都已经关闭了,谁还给你Debug呀

java.lang.IllegalStateException报警相关推荐

  1. java.lang.IllegalStateException: Cannot modify managed objects outside of a write transaction. in /U

    错误内容如下 java.lang.IllegalStateException: Cannot modify managed objects outside of a write transaction ...

  2. 批量下载的实现及java.lang.IllegalStateException异常

    在工作流的一张表单里可能会有多个步骤上传附件,在用户的待办中往往会存在多条带有附件的任务,如果一一打开并且点击下载链接下载,不仅费时,而且繁琐,用户体验较差. OA系统采用的是FastDFS做为文件服 ...

  3. JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    测试又报bug啦 接到测试小伙伴的问题,说是一个接口不返回数据了,好吧,虽然不是我写的接口任务落到头上也得解决,本地调试了一下,好家伙,直接抛了个异常出来,这又是哪位大哥喝醉了写的代码... Exce ...

  4. 订阅者java_RxJava:“java.lang.IllegalStateException:只允许一个订阅者!”

    我正在使用RxJava来计算Android中某些传感器数据的标准化自动关联 . 奇怪的是,我的代码抛出一个异常("java.lang.IllegalStateException:只允许一个订 ...

  5. Tomcat启动之异常java.lang.IllegalStateException

    Tomcat启动之异常java.lang.IllegalStateException 参考文章: (1)Tomcat启动之异常java.lang.IllegalStateException (2)ht ...

  6. Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法

    Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法 参考文章: (1)An ...

  7. java.lang.IllegalStateException: Failed to load ApplicationContext,这个异常的解决方案

    java.lang.IllegalStateException: Failed to load ApplicationContext,这个异常的解决方案 参考文章: (1)java.lang.Ille ...

  8. 解决java.lang.IllegalStateException: getOutputStream() has already been called for this response

    简单的说:用了流之后关掉即可. 下面详细说明: 出现了java.lang.IllegalStateException: getOutputStream() has already been calle ...

  9. ES failed to notify ClusterStateListener java.lang.IllegalStateException: environment is not locked

    ES出现异常: failed to notify ClusterStateListener java.lang.IllegalStateException: environment is not lo ...

  10. Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)

    使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...

最新文章

  1. WinCE下多份BSP的维护技巧
  2. matlab把每次循环的结果保存idx,来自Matlab的循环Python
  3. C#中控制窗体的显示与隐藏
  4. P2756 魔术球问题 (网络流)
  5. 【Linux】一步一步学Linux——cd命令(20)
  6. java线程安全问题原因及解决办法
  7. zabbix监控特定进程
  8. 关于vue中watch和computed
  9. 杭电1434 幸福列车
  10. 14年macmini装双硬盘_19年性价比超高的5款笔记本电脑推荐
  11. 一个button同时执行多个有返回值的函数的解决方法(return false; or return true;)...
  12. 并发情况下使用List,多线程操作List,CopyOnWriteArrayList的使用
  13. 美图为什么布局AR增强现实?
  14. 中国剩余定理-数硬币
  15. Grasshopper不显示gha插件的解决方法
  16. 5.2.1_2 普通心理学(彭冉玲第四版) - 第1章 心理学的研究对象和方法
  17. 硅谷创业天堂的启示!
  18. 新唐(nuvoton)单片机学习资料汇总
  19. golang协程goroutine
  20. ping www.baidu.com虚拟机中ping百度

热门文章

  1. mssql无法通过ip连接mysql_解决ADO通过指定IP地址连接到SQLServer数据库时总是失败问题...
  2. 8.2学长讲解(数论入门)
  3. 软件项目需求调研报告模板下载_「软件项目管理入门」(21) 需求调研和需求分析怎么做?...
  4. 用python写一个简单的贪吃蛇游戏(附代码)
  5. 计算机视觉应用培训心得体会,计算机视觉专题分享总结(附PPT)
  6. python catia 接口_CATIA二次开发工程制图接口:
  7. 路由器刷机教程图解_斐讯路由器K1/K2/K2P系列刷机流程图文教程
  8. 基于EEG的睡眠分期算法记录3-使用决策树多类支持向量机的自动睡眠阶段分类
  9. opencv实现阈值分割
  10. [系统安全] 十五.Chrome密码保存功能渗透解析、Chrome蓝屏漏洞及音乐软件漏洞复现