title: EntityManagerFactory is closed after application restarted with spring-boot-devtools
body: <p>I was looking into many Q&amp;A in StackOverflow, none of them solved my issue or not matching my case. For example the following questions.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/44874114/entitymanagerfactory-is-closed-when-page-is-reloaded">EntityManagerFactory is closed when page is reloaded</a></li>
  <li><a href="https://stackoverflow.com/questions/42065877/entitymanagerfactory-is-closed-hibernate">EntityManagerFactory is closed</a></li>
  <li><a href="https://stackoverflow.com/questions/36445802/entitymanagerfactory-is-closed">EntityManagerFactory is closed</a></li>
  </ul>
  
  <p>What my issue is, 
  I am working on SpringBoot v2.2.5.RELEASE and MariaDB. I have added the spring-boot-devtools in my pom as below.</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My DataSource configuration in application.properties as below</p>
  
  <pre><code>spring.jpa.generate-ddl=false
  spring.jpa.hibernate.ddl-auto = validate
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  spring.datasource.url=jdbc:mysql://xxx.xxx.xxx.xxx/db_name_here?useSSL=false&amp;allowPublicKeyRetrieval=true
  spring.datasource.username=xxx
  spring.datasource.password=xxx
  spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
  </code></pre>
  
  <p>I am running the application with following command via command line</p>
  
  <pre><code>mvn spring-boot:run
  </code></pre>
  
  <p>as expected whenever any files change in the classpath, applications using this spring-boot-devtools cause the application to restart. Once after the application is restarted, if I am trying to relogin to the application, I am getting the below error.</p>
  
  <pre><code>org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException
  : EntityManagerFactory is closed
  // truncated
  Caused by: java.lang.IllegalStateException: EntityManagerFactory is closed
          at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:507) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
  </code></pre>
  
  <p>Only after stopping the process with CTRL+C and re-run the command, the application is working without entity manager issue. Please advice.</p>