3
respostas

Erro ao parar o Servidor

O Servidor inicia normalmente, mas ao clicar no botão "Stop" ocorre o erro descrito abaixo. Gostaria de parar o Servidor sem apresentar erro.

2022-09-11 21:08:47.783 INFO 848 --- [ restartedMain] br.com.alura.forum.ForumApplication : Started ForumApplication in 24.65 seconds (JVM running for 30.127) 2022-09-11 21:10:21.414 INFO 848 --- [nio-8080-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-09-11 21:10:21.414 INFO 848 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-09-11 21:10:21.416 INFO 848 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms 2022-09-11 21:44:53.289 INFO 848 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2022-09-11 21:44:53.379 ERROR 848 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Error thrown while acquiring connection from data source

org.h2.jdbc.JdbcSQLNonTransientConnectionException: The database is open in exclusive mode; can not open additional connections [90135-214] at org.h2.message.DbException.getJdbcSQLException(DbException.java:678) ~[h2-2.1.214.jar:2.1.214] at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) ~[h2-2.1.214.jar:2.1.214] at org.h2.message.DbException.get(DbException.java:223) ~[h2-2.1.214.jar:2.1.214] at org.h2.message.DbException.get(DbException.java:199) ~[h2-2.1.214.jar:2.1.214] at org.h2.message.DbException.get(DbException.java:188) ~[h2-2.1.214.jar:2.1.214] at org.h2.engine.SessionLocal.checkSuspended(SessionLocal.java:1240) ~[h2-2.1.214.jar:2.1.214] at org.h2.engine.SessionLocal.transitionToState(SessionLocal.java:1232) ~[h2-2.1.214.jar:2.1.214] at org.h2.engine.SessionLocal.waitIfExclusiveModeEnabled(SessionLocal.java:1480) ~[h2-2.1.214.jar:2.1.214] at org.h2.command.Command.executeQuery(Command.java:180) ~[h2-2.1.214.jar:2.1.214] at org.h2.jdbc.JdbcConnection.isReadOnly(JdbcConnection.java:538) ~[h2-2.1.214.jar:2.1.214] at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:408) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:726) ~[HikariCP-4.0.3.jar:na] at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:712) ~[HikariCP-4.0.3.jar:na] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

2022-09-11 21:44:53.539 WARN 848 --- [ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-214] 2022-09-11 21:44:53.540 INFO 848 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-09-11 21:44:53.639 INFO 848 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

Process finished with exit code 130

3 respostas

Oi Fabio,

Altera a url de conexão com o banco para:

spring.datasource.url=jdbc:h2:mem:alura-forum;DB_CLOSE_ON_EXIT=FALSE

Após realizar a alteração indicada acima, a quantidade de linhas de erros do Terminal reduziu bastante, porém o erro persiste conforme apresentado abaixo:

2022-09-16 19:53:06.842 INFO 7652 --- [ restartedMain] br.com.alura.forum.ForumApplication : Started ForumApplication in 12.625 seconds (JVM running for 14.124) 2022-09-16 19:56:49.291 INFO 7652 --- [nio-8080-exec-9] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-09-16 19:56:49.293 INFO 7652 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-09-16 19:56:49.305 INFO 7652 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : Completed initialization in 12 ms 2022-09-16 20:01:07.112 INFO 7652 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2022-09-16 20:01:07.424 WARN 7652 --- [ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-214] 2022-09-16 20:01:07.426 INFO 7652 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-09-16 20:01:07.452 INFO 7652 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

Process finished with exit code 130

Na verdade lendo a documentação do H2 a recomendação para banco de dados em memória é utilizar outro parâmetro na url:

;DB_CLOSE_DELAY=-1

Mais detalhes: http://www.h2database.com/html/features.html#in_memory_databases

Veja se com esse parâmetro o problema para de ocorrer ao parar o projeto.