试图在我的java控制台应用程序中配置JPA数据源,它使用了spring和mysql,而且似乎并不是所有定义的属性都能工作:
application.properties
spring.datasource.url=jdbc:mysql://xyz:3306/xyz
spring.datasource.username=xyz
spring.datasource.password=xyz
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
# Below properties don't change transactions behaviour
spring.jpa.properties.hibernate.ddl-auto = create-drop
spring.jpa.properties.javax.persistence.query.timeout=30
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.time-between-eviction-runs-millis=5000
spring.datasource.tomcat.initial-size=1
spring.datasource.tomcat.max-active=1
spring.datasource.tomcat.max-idle=1
spring.datasource.tomcat.max-wait=5000
spring.datasource.tomcat.log-abandoned=truebuild.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
mysqlVersion = '6.0.6'
dbcp2Version = '2.2.0'
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-dbcp2', dbcp2Version
compile group: 'mysql', name: 'mysql-connector-java', version: mysqlVersion
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude module: "tomcat-jdbc"
}
testCompile("org.springframework.boot:spring-boot-starter-test")
}我不能设置查询超时,不能定义每5秒重新连接到db (在放弃连接的情况下)等等。我如何在java控制台应用程序中这样做?
发布于 2018-02-11 21:42:31
看起来您包含了commons-dbcp2和cnfiguring datasource-tomcat。
您可能需要确认您正在使用tomcat连接池。
如果这仍然是一个问题,尝试从您的应用程序属性中删除.tomcat。我找到了同样的东西,然后找到了本文:https://artofcode.wordpress.com/2017/10/19/spring-boot-configuration-for-tomcats-pooling-data-source
https://stackoverflow.com/questions/48187010
复制相似问题