java.sql.SQLException : HikariDataSource HikariDataSource (HikariPool-1) has been closed

标签 java spring

Exception in thread "task-2" org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-1) has been closed.我有一个 SQL 脚本,它只是在应用程序启动时插入一些记录spring.datasource.data=classpath:kana.sql它似乎运行了大约 10-20 就好了然后突然就退出了
我的 application.properties :

## default connection pool
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create

## PostgreSQL
spring.datasource.url=jdbc:postgresql://10.0.0.100:5432/langsite
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driverClassName=org.postgresql.Driver

spring.datasource.initialization-mode=always
spring.datasource.data=classpath:kana.sql

server.port=4000

#drop n create table again, good for testing, comment this in production
# javax.persistence.schema-generation.scripts.action=create
# javax.persistence.schema-generation.create-source=metadata
# javax.persistence.schema-generation.drop-source=metadata

它最初似乎连接成功,因为它可以创建表,插入一些记录,但是在插入过程中它只是胡说八道。

最佳答案

看起来您的应用程序用尽了池中的可用连接。
我想这两件事是矛盾的:
这个

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
和这个
spring.datasource.initialization-mode=always
spring.datasource.data=classpath:kana.sql
如果您想通过 Hibernate 创建模式,请尝试使用此选项来加载初始数据
spring.jpa.properties.hibernate.hbm2ddl.import_files=classpath:kana.sql
无论如何引用这篇文章。它应该有帮助
https://dimitr.im/loading-initial-data-with-spring

关于java.sql.SQLException : HikariDataSource HikariDataSource (HikariPool-1) has been closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63855444/

相关文章:

JavaFX - 由 : java. lang.UnsupportedOperationException : Unable to open DISPLAY? 引起

java - 如何为 Java JDBC EntityManagerFactory 类中的实体设置 ID?

带有自定义 UserDetails 实现的 java.io.NotSerializableException

java - 了解 Spring 3.0 示例中的 Ajax 简化

java - Guice IoC 怎么样?

java - 在测试中断言 java.util.Date 字段

java - 我如何组织我的 Java Eclipse 项目,以便用户只需要执行一次导入?

java - 设置安卓 :windowIsFloating programmatically

java - 使用 JSTL 访问模型对象

java - Spring boot JNDI不工作,tomcat无法启动