GORM 无法从插件中实现域类是 GORM 类 [英] GORM fails to realize Domain classes from a plugin are GORM classes

查看:19
本文介绍了GORM 无法从插件中实现域类是 GORM 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Grails 项目作为插件,以便基本上在插件中包含我的域类,然后在多个 Grails 项目中使用它们.

I am trying to use a Grails Project as a Plugin to basically have my domain classes in the Plugin and then use them in multiple Grails projects.

我已经这样做了:

grails 创建应用程序网络

grails create-app web

grails 创建应用插件

grails create-app plugin

在两个项目的根目录下创建一个settings.gradle包括插件"、网页"

create a settings.gradle in the root directory of both projects with include 'plugin', 'web'

然后我在插件中添加了 spring security 并使用 s2-quickstart 创建了一个用户和一个角色域类,并在 Bootstrap.groovy 中添加了一些默认用户.

then I added spring security to the plugin and used s2-quickstart to create a user and a role domain class and added some default users to the Bootstrap.groovy.

单独启动插件项目不会显示任何问题.

Starting the plugin project alone doesn't show any issues.

现在我将插件添加为 web 项目的依赖项:编译(':插件')这样我就可以从 web 项目中的插件访问域类,它编译得很好.我将 spring 配置添加到 application.groovy 中,现在正在尝试使用 Web 项目中插件中的域类.

Now I added the plugin as a dependency to the web project: compile (':plugin') This way I can access the domain classes from the plugin inside the web project, it compiles fine. I added the spring config to the application.groovy and am now trying to use the domain classes from the plugin inside the web project.

尝试这个但是我的项目没有正确启动它告诉我这个:

Trying this however my project does not correctly start and it tells me this:

java.lang.IllegalStateException: Either class [htcommon.HtRole] is not a domain class or GORM has not been initialized correctly or has already been shutdown. If you are unit testing your entities using the mocking APIs

只要我的代码尝试执行 new HtRole(...).save()

as soon as my code tries to do new HtRole(...).save()

插件中的域类似乎无法识别为 GORM 类.

It seems the domain classes from the plugin are not recognized as GORM classes somehow.

推荐答案

域未被识别为 GORM 类的问题是由于其中提供的构造函数造成的.这些构造函数是从 s2-quickstart 生成的,但应该删除(这是 spring-security-core 中的一个错误).我删除了构造函数和你使用它们的一个地方我使用了 map style default构造函数.然后我修复了您必须获取当前用户的电话.

The issue with the domain not being recognized as a GORM class was due to the constructors provided in them. These constructors were generated from s2-quickstart, but should be removed (it's a bug in spring-security-core). I removed the constructors and the one place you were using them I used map style default constructors. Then I fixed the call you had to get the current user.

修复的源代码在 GitHub 上的这个 repo(patch-1 分支)正在工作,master 是 OP 的原始损坏代码)

The repaired source is in this repo on GitHub (patch-1 branch is working, master is the OP's original broken code)

这篇关于GORM 无法从插件中实现域类是 GORM 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆