GORM无法实现来自插件的域类是GORM类 [英] GORM fails to realize Domain classes from a plugin are GORM classes
问题描述
我试图使用Grails项目作为插件,基本上在插件中有我的域类,然后在多个Grails项目中使用它们。
我已经完成此操作: 使用 然后我为插件添加了spring安全性,并使用s2-quickstart创建用户和角色域类,并向Bootstrap.groovy添加了一些默认用户。
grails create-app web
$ b
在两个项目的根目录下创建settings.gradle包括'plugin','web'
现在我将该插件添加为web项目的依赖项:
compile(':plugin')
这样我可以从Web项目中的插件访问域类,它编译得很好。我将spring配置文件添加到了application.groovy中,并且现在正尝试使用web项目中插件的域类。
尝试此操作但是我的项目不正确开始,它告诉我:
pre $ java.lang.IllegalStateException:任何一个类[htcommon.HtRole]不是一个域类或GORM尚未正确初始化或已关闭。如果您使用模拟API
对您的实体进行单元测试,只要我的代码尝试执行新的HtRole (...)。save()
似乎插件中的域类无法以某种方式被识别为GORM类。
域未被识别为GORM类的问题是由于其中提供了构造函数。这些构造函数是从 s2-quickstart
生成的,但应该删除(这是spring-security-core中的一个错误)。我删除了构造函数和您使用它们的一个地方我使用了地图样式默认构造的。然后我解决了你必须得到当前用户的电话。
修复过的源代码在GitHub上的这个回购站(patch-1分支正在运行,master是OP的原始代码)
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.
I've done this:
grails create-app web
grails create-app plugin
create a settings.gradle in the root directory of both projects with include 'plugin', 'web'
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.
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
as soon as my code tries to do new HtRole(...).save()
It seems the domain classes from the plugin are not recognized as GORM classes somehow.
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.
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屋!