微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 如何使用Grails 3.0配置PostgreSQL?

我使用IntelliJ IDEA 15.0.2作为IDE.我已经创建了一个Grails 3.0应用程序,并对其进行了一些更改以配置Postgresql.

这是我的dataSource:

dataSource:
pooled: true
jmxexport: true
driverClassName: org.postgresql.Driver
username: postgres
password: root

environments:
development:
    dataSource:
        dbCreate: update
        url: jdbc:postgresql://localhost:5432/trace_db
test:
    dataSource:
        dbCreate: update
        url: jdbc:postgresql://localhost:5432/trace_db
production:
    dataSource:
        dbCreate: update
        url: jdbc:postgresql://localhost:5432/trace_db
        properties:
            jmxenabled: true
            initialSize: 5
            maxActive: 50
            minIdle: 5
            maxIdle: 25
            maxWait: 10000
            maxAge: 600000
            timeBetweenevictionRunsMillis: 5000
            minevictableIdleTimeMillis: 60000
            validationQuery: SELECT 1
            validationQueryTimeout: 3
            validationInterval: 15000
            testOnBorrow: true
            testWhileIdle: true
            testOnReturn: false
            jdbcInterceptors: ConnectionState
            defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

在我的build.gradle中,我添加了运行时“postgresql:postgresql:9.4-1207.jdbc4”.

但是当我跑步时会出错:

ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.sqlException: org.postgresql.Driver

我错过了什么?

解决方法:

数据源

dataSource {
    pooled = true
    jmxexport = true
    driverClassName = "org.postgresql.Driver"
    username = "postgres"
    password = "xxx"

构建配置

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
        // runtime 'MysqL:mysql-connector-java:5.1.29'
        // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
        runtime "org.postgresql:postgresql:9.4.1208.jre7"
        test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
    }

根据db numbe psql版本更改jre编号.
希望我帮忙.干杯!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐