grails 在运行 grails generate 命令时抛出异常

标签 grails grails-orm

我在本地运行 grails 2.4.4。我有以下域类:

class MyClass {

    byte[] posterImage
    String posterType
    String posterName
    static belongsTo = NicheChannel
    static constraints = {
        posterImage(nullable: true, maxSize: 16384000 /* 16000k */)
        posterType(nullable: true)
    }
}

当我尝试运行时
grails generate-controller MyClass 

或者
grails generate-views MyClass

我得到以下异常:
| Domain class not found in grails-app/domain, trying hibernate mapped classes...
| Error 2016-01-04 04:30:44,365 [main] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@1cce5986 returned null for URL:jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
  Line | Method
->> 40 | doCall in _GrailsBootstrap$_run_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   64 | doCall in _GrailsBootstrap$_run_closure6
|   45 | doCall in _GrailsGenerate_groovy$_run_closure1
^   40 | doCall in GenerateViews$_run_closure1
| Error 2016-01-04 04:30:44,400 [main] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@269f379b returned null for URL:jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
  Line | Method
->> 40 | doCall in _GrailsBootstrap$_run_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   64 | doCall in _GrailsBootstrap$_run_closure6
|   45 | doCall in _GrailsGenerate_groovy$_run_closure1
^   40 | doCall in GenerateViews$_run_closure1
| Error 2016-01-04 04:30:44,431 [main] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@20ed4023 returned null for URL:jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
  Line | Method
->> 40 | doCall in _GrailsBootstrap$_run_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   64 | doCall in _GrailsBootstrap$_run_closure6
|   45 | doCall in _GrailsGenerate_groovy$_run_closure1
^   40 | doCall in GenerateViews$_run_closure1
| Error Error executing script GenerateViews: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: Driver:org.postgresql.Driver@20ed4023 returned null for URL:jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE (Use --stacktrace to see the full trace)

我什至试过
grails generate-all MyClass

我得到了同样的异常(exception)。

最佳答案

更新:通过将包名附加到 MyClass 来解决这个问题,如下所示

grails generate-controller <packagename>.MyClass 

关于grails 在运行 grails generate 命令时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588154/

相关文章:

grails - 在运行时更改ActiveMQConnectionFactory brokerURL在grails中

grails - 如何在gsp中的复选框值上动态加载表

grails - 一个 Grails 域类中的多个多对多关联

hibernate - Grails Controller "show"操作导致 2 个带有 "unique"约束的选择查询

rest - 设计问题 : how to create a restful interface made out of multiple domain objects?

Grails - Controller 和 View 之间的通信

grails - 对视频格式进行编码

grails - 如何在Grails过滤器中获取 Controller 类

grails - 更改 GORM 数据库列

mysql - 将类型从简单字符串更改为文本后的 Grails - 第 1 行的 'text' 列的数据太长