【发布时间】:2017-10-03 15:25:13
【问题描述】:
我有一个包含两个数据库的应用程序。
Mongo 的主要部分和与 Postgres 之一的连接。
在生产环境中,postgres 在外部服务器中的连接(Mongo 在同一台机器上)。
当我部署它时,如果它正确地将我连接到 Postgres 的数据库,但是当它发生一点时间就会失去连接并且不再恢复它。
为了不关闭连接我应该玩什么参数?
spring:
devtools:
restart:
enabled: false
livereload:
enabled: false
data:
mongodb:
uri: mongodb://xxxxx:27017
database: xxx
datasources:
elser:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://222.21.224.337:5432/xxx
username: username
password: password
mail:
host: localhost
port: 25
username:
password:
thymeleaf:
cache: true
jpa:
show-sql: true
database-platform: io.github.jhipster.domain.util.FixedPostgreSQL82Dialect
database: POSTGRESQL
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.dialect: org.hibernate.dialect.PostgreSQL82Dialect
【问题讨论】:
-
Spring Boot 在检测到非内存数据库时尝试使用连接池。默认池as explained here 是Tomcat 提供的。因此,除非您提供自己的连接池,否则设置
spring.datasource.tomcat.test-on-borrow=true将强制 Tomcat 在将代码交给它之前测试连接,如果连接无效,请替换它。但是,请注意,大多数池因无法正确从故障中恢复而臭名昭著。
标签: jpa spring-boot spring-data-jpa