如何使用Grails 3.0配置PostgreSQL?

Sye*_*med 5 java postgresql grails jdbc intellij-idea

我使用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
Run Code Online (Sandbox Code Playgroud)

在我的build.gradle补充中runtime "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
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

小智 5

数据源

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.postgresql.Driver"
    username = "postgres"
    password = "xxx"
Run Code Online (Sandbox Code Playgroud)

构建配置

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"
    }
Run Code Online (Sandbox Code Playgroud)

根据您的 db numbe psql 版本更改 jre 编号。希望我有所帮助。干杯!