首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不是所有在控制台应用程序中工作的Spring和数据源属性

不是所有在控制台应用程序中工作的Spring和数据源属性
EN

Stack Overflow用户
提问于 2018-01-10 11:59:31
回答 1查看 524关注 0票数 1

试图在我的java控制台应用程序中配置JPA数据源,它使用了spring和mysql,而且似乎并不是所有定义的属性都能工作:

application.properties

代码语言:javascript
复制
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=true

build.gradle

代码语言:javascript
复制
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控制台应用程序中这样做?

EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48187010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档