【发布时间】: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