Grails find / findAll 操作不起作用?
我正在尝试构建一个可以执行 LDAP 查找的 Grails 应用程序。我一直在遵循一些指南(链接文本 和其他一些指南)但恐怕没有尽头。
相关源码: 来自 config.groovy:
ldap {
directories {
dir1 {
url = "ldap://dc01"
base = "ou=someou,dc=check,dc=nl"
userDn = "cn=Administrator,cn=Users,dc=check,dc=nl"
password = "wowthisisnothepassword"
}
}
schemas = [
ldapclient.GldapoSchemaClassForUser
]}
我的域类:
package ldapclient
import gldapo.schema.annotation.GldapoNamingAttribute
import gldapo.schema.annotation.GldapoSynonymFor
import gldapo.schema.annotation.GldapoSchemaFilter
@GldapoSchemaFilter("(objectclass=person)")
class GldapoSchemaClassForUser {
@GldapoNamingAttribute
String uid
@GldapoSynonymFor("cn")
String name
@GldapoSynonymFor("mail")
String email
@GldapoSynonymFor("uid")
String username
@GldapoSynonymFor("fullname")
String fullName
}
和我的控制器:
package ldapclient
class AdController {
def defaultAction = "list"
List matches = GldapoSchemaClassForUser.findAll(
filter: "(name=s*)"
)
def list = {
[ "adMatches" : matches.list() ]
}}
虽然我的程序符合(据我所知)根据许多文档应该工作的内容,但我无法运行它。抛出的错误:
由以下原因引起:groovy.lang.MissingMethodException:没有方法签名:static ldapclient.GldapoSchemaClassForUser.findAll() 适用于参数类型:(java.util.LinkedHashMap) 值:[[filter:(name =s)]] 在 ldapclient.AdController.(AdController.groovy:6)*
有任何线索发生了什么/错误吗?我使用的是 Grails 1.2.3 并使用最新版本的 LDAP 插件。该项目是干净的(新创建的)。
提前致谢!
感谢您的回复;我刚刚升级到 Grails 1.3.4 并移动了一些文件。这确实有一些好处,但我仍然遇到这个令人讨厌的错误:
Error creating bean with name 'ldapclient.AdController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ldapclient.AdController]: Constructor threw exception; nested exception is groovy.lang.MissingMethodException: No signature of method: static ldapclient.GldapoSchemaClassForUser.findAll() is applicable for argument types: (java.util.LinkedHashMap) values: [[directory:dir1, filter:(uid=myname,ou=st,ou=ouou,dc=dc,dc=dcdc)]] Possible solutions: findAll(groovy.lang.Closure), find(groovy.lang.Closure)
I'm trying to build a Grails application which can do LDAP lookups. I've been following a few guides (link text and some others) but to no end I'm afraid.
Relevant source code:
From config.groovy:
ldap {
directories {
dir1 {
url = "ldap://dc01"
base = "ou=someou,dc=check,dc=nl"
userDn = "cn=Administrator,cn=Users,dc=check,dc=nl"
password = "wowthisisnothepassword"
}
}
schemas = [
ldapclient.GldapoSchemaClassForUser
]}
My domainclass:
package ldapclient
import gldapo.schema.annotation.GldapoNamingAttribute
import gldapo.schema.annotation.GldapoSynonymFor
import gldapo.schema.annotation.GldapoSchemaFilter
@GldapoSchemaFilter("(objectclass=person)")
class GldapoSchemaClassForUser {
@GldapoNamingAttribute
String uid
@GldapoSynonymFor("cn")
String name
@GldapoSynonymFor("mail")
String email
@GldapoSynonymFor("uid")
String username
@GldapoSynonymFor("fullname")
String fullName
}
And my controller:
package ldapclient
class AdController {
def defaultAction = "list"
List matches = GldapoSchemaClassForUser.findAll(
filter: "(name=s*)"
)
def list = {
[ "adMatches" : matches.list() ]
}}
Although my program conforms (for as far as I can tell) to what should work according to the many documents, I cannot run this. The error thrown:
Caused by: groovy.lang.MissingMethodException: No signature of method: static ldapclient.GldapoSchemaClassForUser.findAll() is applicable for argument types: (java.util.LinkedHashMap) values: [[filter:(name=s)]]
at ldapclient.AdController.(AdController.groovy:6)*
Any clues what's going on / wrong? I'm on Grails 1.2.3 and using the most current version of the LDAP plugin. The project is clean (freshly created).
Thanks in advance!
Thanks for the response; I just upgraded to Grails 1.3.4 and moved some files around. This did some good, though I still get this nasty error:
Error creating bean with name 'ldapclient.AdController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ldapclient.AdController]: Constructor threw exception; nested exception is groovy.lang.MissingMethodException: No signature of method: static ldapclient.GldapoSchemaClassForUser.findAll() is applicable for argument types: (java.util.LinkedHashMap) values: [[directory:dir1, filter:(uid=myname,ou=st,ou=ouou,dc=dc,dc=dcdc)]] Possible solutions: findAll(groovy.lang.Closure), find(groovy.lang.Closure)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的架构类位于哪里?我有这个插件工作正常(尽管使用 Grails 1.3.4)。请注意,您的插件链接是一个旧页面。这是我认为的最新版本:Grails LDAP 插件。
不要认为有太大区别,除了看起来您可以将架构类放入 grails-app/ldap 目录中,而不必在 Config 中指定它们 - 我的做法与您相同配置中指定的模式,但可能值得在 grails-app/ldap 文件夹中尝试它们?
Where are your schema classes located? I have this plugin working fine (albeit with Grails 1.3.4). Note that your link to the plugin is an old-ish page. Here is the latest I believe: Grails LDAP Plugin.
Don't think there's much difference other than it looks like you can drop schema classes in the grails-app/ldap directory instead of having to specify them in Config - I do it the same way as you with schemas specified in the config, but might be worth trying them in the grails-app/ldap folder?
根据文档,findAll方法只有这个定义(其中Book - 是示例域class):
并且您的代码:
可以重写为:
或使用 条件定义:
要使用过滤器 - 请查看 Hibernate-filter 插件
According to documentation, findAll method has only this definitions (where Book - is sample domain class):
And your code:
Could be rewritten as:
Or use criteria definition:
To use filters - look at Hibernate-filter plugin
我在使用 grails 2.2 和 ldap 插件 0.8.2 的几天里遇到了同样的问题。在深入研究 gldapo 邮件列表存档后,我发现出现这种情况是因为模式类没有注入 gldapo 行为,因此 find/findAll() 方法未正确解析。请参阅此线程 - http://markmail.org/message/v5ulptrxzfoq4ml7
我错过了使用 'import myPkg我的 grails Config.groovy 脚本中的 .SchemaClass' 。
I had the same problem for a couple of days using grails 2.2 with ldap plugin 0.8.2. After digging through the gldapo mailing list archive, I found out that this occurs because the schema class is not injected with Gldapo behavior and hence the find/findAll() methods are not resolved correctly. Refer to this thread - http://markmail.org/message/v5ulptrxzfoq4ml7
I had missed using 'import myPkg.SchemaClass' in my grails Config.groovy script.