【问题标题】:Grails find / findAll operation won't work?Grails find/findAll 操作不起作用?
【发布时间】:2010-09-30 21:26:13
【问题描述】:

我正在尝试构建一个可以进行 LDAP 查找的 Grails 应用程序。我一直在关注一些指南(link text 和其他一些指南),但恐怕没有尽头。

相关源码: 来自 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:没有方法签名:静态 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)

【问题讨论】:

    标签: grails groovy active-directory ldap findall


    【解决方案1】:

    您的架构类位于何处?我有这个插件工作正常(尽管使用 Grails 1.3.4)。请注意,您指向插件的链接是一个旧页面。这是我相信的最新消息:Grails LDAP Plugin

    除了看起来您可以将架构类放在 grails-app/ldap 目录中而不必在 Config 中指定它们之外,别认为有太大区别 - 我也是这样做的就像您在配置中指定的架构一样,但可能值得在 grails-app/ldap 文件夹中尝试它们?

    【讨论】:

      【解决方案2】:

      According to documentation,findAll 方法只有这个定义(其中 Book - 是示例域类):

      Book.findAll()
      Book.findAll( String query )
      Book.findAll( String query, Collection positionalParams )
      Book.findAll( String query, Collection positionalParams, Map paginateParams )
      Book.findAll( String query, Map namedParams )
      Book.findAll( String query, Map namedParams, Map paginateParams )
      Book.findAll( Book example )
      

      还有你的代码:

      List matches = GldapoSchemaClassForUser.findAll(
          filter: "(name=s*)"
      )
      

      可以改写为:

      List matches = GldapoSchemaClassForUser.findAllByNameLike("s%")
      

      或者使用criteria definition:

      List matches = GldapoSchemaClassForUser.list() {
           like("name","s%")
      }
      

      要使用过滤器 - 查看Hibernate-filter plugin

      【讨论】:

      【解决方案3】:

      我在使用带有 ldap 插件 0.8.2 的 grails 2.2 时遇到了同样的问题。在挖掘 gldapo 邮件列表存档后,我发现这是因为架构类没有注入 Gldapo 行为,因此 find/findAll() 方法没有正确解析。参考这个帖子-http://markmail.org/message/v5ulptrxzfoq4ml7

      我错过了在我的 grails Config.groovy 脚本中使用“import myPkg.SchemaClass”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-19
        • 2016-09-30
        • 2021-11-28
        • 2012-08-30
        • 2014-07-28
        相关资源
        最近更新 更多