【问题标题】:Use Domain Classes from a Plugin使用插件中的域类
【发布时间】:2017-07-12 08:10:58
【问题描述】:

我目前正在尝试第一次 grails 3。

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

现在我收到以下错误:

Caused by: java.lang.IllegalStateException: Either class [de.foo.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

作者域类:

class Author { 
  String name 
}

我正在取消具有以下依赖项的 Grails 3.2.9:

插件

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"

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

【问题讨论】:

  • 什么时候出现这个错误? 100% 确定:插件和应用程序中的 grails 版本相同?
  • 是插件和应用程序中的相同版本。我在运行应用程序时遇到此错误。
  • 好吧,grails 版本是一样的,但 GORM 版本不一样。将两者设置为相同的版本解决了问题

标签: grails grails-orm grails3


【解决方案1】:

对于 GORM 错误,版本必须相同。对于其他 grails 的东西,groovy 版本通常必须相同才能实现二进制兼容性。虽然并非 100% 要求在每种情况下都保持每个版本相同,但在 grails 3 中比在 grails 2 中更需要,并且可能只是目前的最佳实践。

【讨论】:

  • “虽然不是 100% 需要在每种情况下保持每个版本相同,但在 grails 3 中比在 grails 2 中更需要” - 事实并非如此。 Grails 3 使您可以轻松(有意地)混合和匹配不同版本的事物。事实上,在最近的 Grails 3 版本中,我们专门将 GORM 版本提取到一个属性文件中,这样您就可以独立于应用程序的其余部分升级该依赖项。
  • 那我的措辞不好。所有插件以及您的应用程序都必须(或最好)具有相同版本的 gorm。或相同版本的 groovy 或 grails。例如,在 grails 2 中,(通常)在 2.3.9 上拥有插件并在 2.5.1 上拥有应用程序并不是什么大问题。现在......这是一件大事。
  • 幸运的是,现在选择不同的版本要容易得多,我同意。如果您使用的是未选择该版本的第三方插件,那会有点痛苦,但这是另一个论坛的讨论。 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
相关资源
最近更新 更多