出现“无法验证新建立的连接”错误。
我用谷歌搜索并阅读了与此错误相关的每个问题。但未能找到解决方案。
我正在使用 spring-boot-starter-data-jpa
。
它在 Postgresql 上没有任何错误。但是我想用嵌入式数据库!!!
application.properties:
#We don't need JMX here - disabling it allows for faster startup
spring.jmx.enabled=false
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.datasource.url=jdbc:hsqldb:file:${user.home}/db/data;user=sa;password=123;
spring.datasource.username=sa
spring.datasource.password=123
MainApplication 类的标题:
@ComponentScan(value = {"db", "app", "ui"})
@EnableJpaRepositories(basePackages = "db")
@EntityScan(basePackages = "db")
@EnableTransactionManagement
@SpringBootApplication
此错误仅在我使用嵌入式数据库(至少是 Derby、HSQLDB)时抛出,并非总是如此。有时启动正常,查找并保存实体没有错误,但有时等待一段时间后或交易成功后立即出现。
我该如何解决这个问题?
最佳答案
您的验证查询是问题所在。虽然没有 FROM
的 SELECT 1
在 Postgres
中有效,但在 hsqldb 中无效。
查看此 answer针对不同数据库的建议验证查询
关于java - 无法验证新建立的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33100423/