将grails 2.3.4部署到heroku - 加载DataSource.groovy时出错

时间:2014-05-14 10:06:05

标签: grails heroku grails-2.3

我想将grails应用程序部署到heroku。

我已经创建了一个堆栈,现在我想要推送它:git push heroku master

但是,我收到了:

       Done precompiling AST Transformations!
       | Compiling 3 source files
       | Compiling 3 source files.
       | Compiling 3 source files..
       | Compiling 3 source files...
       | Compiling 3 source files....
       | Compiling 3 source files.....
-----> Executing ./grailsw -plain-output -Divy.default.ivy.user.dir=/app/tmp/cac
he war --non-interactive
       |Loading Grails 2.3.4
       |Configuring classpath
       .
       |Environment set to production
       .................................
       |Packaging Grails application
       Precompiling AST Transformations ...
       src /tmp/build_f6c7df12-acc1-407e-84b0-95928c52c3ff/target/work/plugins/p
ostgresql-extensions-0.6.1 /tmp/build_f6c7df12-acc1-407e-84b0-95928c52c3ff/targe
t/classes
       Done precompiling AST Transformations!
       ..
       |Compiling 3 source files
       ..................Error
       |
       Error packaging application: Error loading DataSource.groovy: 1 (Use --st
acktrace to see the full trace)
 !     Failed to build app

 !     Push rejected, failed to compile Grails app

To git@heroku.com:quiet-coast-2715.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:quiet-coast-2715.git'

我认为我的数据源已损坏,所以我认为我的DataSource.groovy

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = org.hibernate.dialect.PostgreSQLDialect
    username = "admin"
    password = "******"
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    //    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}

// environment specific settings
environments {

//...

    production {
        dataSource {
            dbCreate = "update"
            driverClassName = "org.postgresql.Driver"
            dialect = org.hibernate.dialect.PostgreSQLDialect

            uri = new URI(System.env.DATABASE_URL?:"postgres://myHerokuUsername:myPassoword@5432/TestDB")

            url = "jdbc:postgresql://"+uri.host+uri.path
            username = uri.userInfo.split(":")[0]
            password = uri.userInfo.split(":")[1]
        }
    }
}

此外,我还添加了BuildConfig.groovy

runtime postgresql:postgresql:8.4-702.jdbc3'

我在数据源中看不到我做错了什么?

感谢您的回答!

PS:如何在git中获得完整的堆栈跟踪?

1 个答案:

答案 0 :(得分:2)

URI Class采用[user-info@]host[:port]语法,您提供的电子邮件地址本身带有@符号,这就是uri.hosturi.userInfo为空的原因构建失败。

尝试打印uri.hosturi.userInfo,您可以看到这些是空的。 在数据源中添加以下代码

dataSource {
  ...
  uri = new URI(System.env.DATABASE_URL ?: "postgres://test@gmail.com:pass@5432/TestDB")
  println "---1---${uri}---${uri.host}---${uri.path}---${uri.userInfo}---"
  url = "jdbc:postgresql://" + uri.host + uri.path
  ...
}

要解决此问题,请为您的用户名和密码选择不包含@符号的字符串。我已将test作为用户名pass作为密码。像:

uri = new URI(System.env.DATABASE_URL ?: "postgres://test:pass@5432/TestDB")

它有效。