【问题标题】:SpringBoot applications keeps rebooting all the time (restart loop) - spring.devtoolsSpring Boot 应用程序一直在重启(重启循环) - spring.devtools
【发布时间】:2018-01-30 10:55:49
【问题描述】:

我有一个带有嵌入式 tomcat 的 Spring Boot 应用程序,如果类路径中发生更改,我可以使用 spring-boot-devtools 重新启动应用程序。

我的 IDE 是 Spring Tool Suite,我切换了“自动构建”,因为我认为这可能会更改触发重启的后台文件

我的问题是tomcat和应用程序启动后立即无限循环重启一切:

2017-08-22 10:24:04.309  INFO 9772 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8055 (http)
2017-08-22 10:24:04.415 DEBUG 9772 --- [  restartedMain] o.s.boot.devtools.restart.Restarter      : Creating new Restarter for thread Thread[main,5,main]
2017-08-22 10:24:04.417 DEBUG 9772 --- [  restartedMain] o.s.boot.devtools.restart.Restarter      : Immediately restarting application
2017-08-22 10:24:04.418 DEBUG 9772 --- [  restartedMain] o.s.boot.devtools.restart.Restarter      : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@558f3be6
2017-08-22 10:24:04.419 DEBUG 9772 --- [  restartedMain] o.s.boot.devtools.restart.Restarter      : Starting application test.web.MyApplication with URLs 
2017-08-22 10:24:04.421  INFO 9772 --- [  restartedMain] test.web.MyApplication                 : Started MyApplication in 22.347 seconds (JVM running for 24.103)
2017-08-22 10:24:05.524 DEBUG 9772 --- [   File Watcher] o.s.boot.devtools.restart.Restarter      : Restarting application
2017-08-22 10:24:05.527 DEBUG 9772 --- [       Thread-9] o.s.boot.devtools.restart.Restarter      : Stopping application
2017-08-22 10:24:05.527  INFO 9772 --- [       Thread-9] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@68f499a9: startup date [Tue Aug 22 10:23:43 CEST 2017]; root of context hierarchy
2017-08-22 10:24:05.529  INFO 9772 --- [       Thread-9] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-08-22 10:24:05.537  INFO 9772 --- [       Thread-9] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-08-22 10:24:05.539  INFO 9772 --- [       Thread-9] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-08-22 10:24:05.567  INFO 9772 --- [       Thread-9] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2017-08-22 10:24:05.864  INFO 9772 --- [ost-startStop-2] org.apache.wicket.Application            : [wicket-filter] destroy: DevUtils DebugBar Initializer
...
2017-08-22 10:44:04.309  INFO 9772 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8055 (http)
...
2017-08-22 10:44:04.421  INFO 9772 --- [  restartedMain] test.web.MyApplication                 : Started MyApplication in 22.347 seconds (JVM running for 24.103)
2017-08-22 10:44:05.527 DEBUG 9772 --- [       Thread-9] o.s.boot.devtools.restart.Restarter      : Stopping application

Workaroud:我知道spring.devtools.restart.enabled = false 可以阻止这种行为,但如果确实有必要,我当然希望重新启动

问题:

  • 如何找出是哪个文件更改触发了重启?
  • 有人遇到过类似问题吗?

【问题讨论】:

  • 它会立即在无限循环中重新启动所有内容:无限循环??
  • 是的,这是一个无限循环。我只在日志中显示了启动和停止,但停​​止后一切都重新开始。
  • Tomcat 可能会将您的应用程序作为服务启动,并且您的应用程序可能会迅速退出(您的主要方法在做什么?)。换句话说It's not a bug, it's a feature。而且您已经知道如何禁用它。
  • 它不仅退出,而且重新开始。该应用程序不是服务,而是启动了一个 apache wicket Web 应用程序。对于一位同事,它在没有该属性的情况下工作(他使用的是 Mac),对于另外两个同事,它正在重新启动(Windows)。好吧,我知道如何禁用它,但如果我更改文件,我希望重新启动。
  • 这里有什么解决办法吗?我对 Windows 也有同样的问题。

标签: java spring-boot


【解决方案1】:

好的,我在应用程序启动几秒钟后通过 Spring Boot DevTools 发现了与我们的应用程序重新启动有关的问题。

DevTools 扫描了日志文件夹,由于应用程序启动后将日志写入该文件夹,因此每次启动都会通过 DevTools 触发整个应用程序的重新加载。

解决办法是在application.yml中将日志文件夹排除在监控之外:

spring:
  devtools:
    restart:
      exclude: logs/**

如果您使用的是普通属性文件,它只是相同的,但中间有 (.) 点。另请参阅http://www.logicbig.com/tutorials/spring-framework/spring-boot/restart-exclude/ 以供参考。

【讨论】:

    【解决方案2】:

    我已经添加了 application.properties,然后它工作正常。周全

    spring.devtools.restart.additional-exclude=logs/**
    

    【讨论】:

      【解决方案3】:

      在 IntelliJ Idea IDE 中

      Edit Run/Debug Configurations...-> 选择您的 Spring Boot 服务项(在左侧面板中)-> 设置运行应用程序更新策略:

      • 在“更新”操作中:什么都不做
      • 关于“框架停用”:什么都不做

      【讨论】:

        猜你喜欢
        • 2020-03-08
        • 1970-01-01
        • 2019-06-17
        • 1970-01-01
        • 2018-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多