Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot applications keeps rebooting all the time (restart loop) - spring.devtools

I have a spring boot application with an embedded tomcat and make use of spring-boot-devtools to restart application if something changed in classpath.

My IDE is Spring Tool Suite and I switched of "Build Automatically" as I thought this could change files in the background which triggers the restart

My problem is that after tomcat and application ist started it immediately restart everything in an infinite loop:

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: I know with spring.devtools.restart.enabled = false I can stop this behaviour but of course I would like the restart if it's really necessary

Question:

  • How to find out which file change triggers the restart?
  • Anybody had similar issues?
like image 339
timguy Avatar asked Aug 22 '17 08:08

timguy


People also ask

Why do we use DevTools in spring boot?

Spring Boot 1.3 provides another module called Spring Boot DevTools. DevTools stands for Developer Tool. The aim of the module is to try and improve the development time while working with the Spring Boot application. Spring Boot DevTools pick up the changes and restart the application.

How does spring boot DevTools work?

Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE as it gives a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder will be monitored for changes.

How do I enable spring DevTools?

To enable dev tools in the spring boot application is very easy. Just add the spring-boot-devtools dependency in the build file.


2 Answers

Okay, I found the problem related to our application restart via Spring Boot DevTools after some seconds just after the application started.

The log file folder was scanned by DevTools and because the application writes logs to this folder after starting, each start triggered a reload of the whole application via DevTools.

The solution is to exclude the log folder from the monitoring within the application.yml:

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

If you´re using normal property files, it´s just the same but with (.) dots in between. See also http://www.logicbig.com/tutorials/spring-framework/spring-boot/restart-exclude/ for reference.

like image 106
Tobias Avatar answered Sep 17 '22 15:09

Tobias


I have added in application.properties, then it was working fine. TQ

spring.devtools.restart.additional-exclude=logs/**
like image 21
zaini Avatar answered Sep 17 '22 15:09

zaini