0

我想在可搜索中包含域角色。因此,如果我使用 User.search() 并输入权限值,系统将显示记录。

我有3个域如下:

class User {
    String username
    String password
    Employee employee
    boolean accountLocked
    boolean passwordExpired

    static hasMany = [userRoles:UserRole];

    static searchable ={
        only:['username','employee','userRoles'];
        employee component:true;
        userRoles component:true;   
    }
}


class UserRole implements Serializable {

    static belongsTo = [user:User,role:Role];

    static searchable = {
       only:['role'];
       role component: true;
    }
}


class Role {
    String authority
    AccessLevel accessLevel
    ProjectName projectName

    static hasMany = [userRoles:UserRole]

    static searchable = {
       only:['authority'];
    }
}

运行应用程序时出现此错误。

Error 2013-12-03 14:39:02,964 [pool-7-thread-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'compassGps': Cannot resolve reference to bean 'compass' while setting bean property 'compass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
Message: Error creating bean with name 'compassGps': Cannot resolve reference to bean 'compass' while setting bean property 'compass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
->> 362 | validateOptions in grails.plugin.searchable.internal.compass.mapping.ClosureSearchableGrailsDomainClassCompassClassMapper
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   242 | invokeMethod in     ''
|    15 | doCall . in com.atigus.admin.security.UserRole$__clinit__closure1
|    97 | searchableGetCompassClassPropertyMappings in grails.plugin.searchable.internal.compass.mapping.ClosureSearchableGrailsDomainClassCompassClassMapper
|   129 | getCompassClassMapping in     ''
|    93 | getCompassClassMapping in grails.plugin.searchable.internal.compass.mapping.CompositeSearchableGrailsDomainClassCompassClassMapper
|    52 | getCompassClassMapping in grails.plugin.searchable.internal.compass.mapping.AbstractSearchableGrailsDomainClassCompassClassMapper
|    80 | configureMappings in grails.plugin.searchable.internal.compass.config.mapping.SearchableClassPropertySearchableGrailsDomainClassMappingConfigurator
|   131 | configure in grails.plugin.searchable.internal.compass.config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator
|    39 | configure in grails.plugin.searchable.internal.compass.config.CompositeSearchableCompassConfigurator
|    93 | buildCompass in grails.plugin.searchable.internal.compass.spring.SearchableCompassFactoryBean
|    58 | getObject in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread

不知道如何解决这个问题。谷歌没有找到答案。

4

1 回答 1

0

我认为您的用户角色类中的可搜索参数无效。
最初只是static searchable = true
在用户角色域中尝试。这应该足够了。

于 2013-12-03T09:01:51.110 回答