Grails 使用插件中的域类

Grails 使用插件中的域类,grails,gorm,grails3,Grails,Gorm,Grails3,我目前正在尝试第一次Grails3 我创建了一个插件,它应该包含一些域类和一个简单的应用程序 现在我得到了以下错误: 原因:java.lang.IllegalStateException:类[de.foo.Author]不是域类,或者GORM未正确初始化或已关闭。在调用GORM实体上的任何方法之前,确保正确加载和配置GORM 作者域类: class Author { String name } 我正在使用以下依赖项运行Grails 3.2.9: 插件 应用 你们对我如何在插件中存储域类

我目前正在尝试第一次Grails3

我创建了一个插件,它应该包含一些域类和一个简单的应用程序

现在我得到了以下错误:

原因:java.lang.IllegalStateException:类[de.foo.Author]不是域类,或者GORM未正确初始化或已关闭。在调用GORM实体上的任何方法之前,确保正确加载和配置GORM

作者域类:

class Author { 
  String name 
}
我正在使用以下依赖项运行Grails 3.2.9:

插件

应用


你们对我如何在插件中存储域类并在某些应用程序中使用它有什么建议或答案吗?

对于GORM错误,版本必须相同。对于其他grails内容,groovy版本通常必须相同,以实现二进制兼容性。虽然并非所有情况下都要求保持每个版本都相同,但在grails 3中,这比在grails 2中更为必要,这可能是目前的最佳实践。

什么时候会出现这种错误?100%确定:插件和应用程序中的grails版本相同?是的,插件和应用程序中的grails版本相同。我在运行应用程序时遇到这个错误。grails版本是相同的,但GORM版本不一样。将两者设置为相同的版本解决了这个问题虽然并非100%需要在所有情况下保持每个版本相同,但在grails 3中比在grails 2中更需要这样做-事实并非如此。Grails3使您可以轻松地混合和匹配不同版本的东西。事实上,在最近的Grails3版本中,我们已经将GORM版本拉到了一个属性文件中,这样你就可以独立于应用程序的其余部分来升级该依赖关系。所有插件和应用程序都必须或最好使用相同版本的gorm。或与groovy或grails相同的版本。例如,在Grails2中,通常在2.3.9上有一个插件,在2.5.1上有一个应用程序并不是什么大问题。现在…这是一件大事。幸运的是,现在选择不同的版本要容易得多,我同意。如果您使用的第三方插件没有选择该版本,这会有点痛苦,但这是另一个论坛的讨论:-
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
console "org.grails:grails-console"
profile "org.grails.profiles:web-plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.3.Final"
compile "org.hibernate:hibernate-ehcache:5.1.3.Final"

compile 'org.grails.plugins:spring-security-cas:3.0.0'
compile 'org.grails.plugins:spring-security-core:3.1.2'

compile "org.apache.poi:poi:3.16"
compile "org.apache.poi:poi-ooxml:3.16"
compile "org.apache.poi:ooxml-schemas:1.0"

compile 'org.grails.plugins:wkhtmltopdf:1.0.0.RC7'
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.3.Final"
compile "org.hibernate:hibernate-ehcache:5.1.3.Final"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.1"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
runtime "com.h2database:h2"

compile "de.foo:bar:0.1"

runtime 'com.bertramlabs.plugins:asset-pipeline-grails:2.14.3'
assets 'com.bertramlabs.plugins:less-asset-pipeline:2.14.3'

runtime "mysql:mysql-connector-java:5.1.29"