" GroovyRuntimeException:找不到匹配的构造函数..."无意义的签名

时间:2017-12-22 12:50:10

标签: grails groovy

Grails 3.2.11

我试图定义枚举来保存我的自定义角色组'和角色'我的服务类中的名称和权限:

import grails.transaction.Transactional

@Transactional
class UserService {

    enum RoleEnum{
        ROLE_SUPERADMIN,
        ROLE_ADMIN,
        ROLE_RECEPTION,
        ROLE_HOUSEKEEPING,
        ;
    }
    enum RoleGroupEnum {
        ROLEGROUP_SUPERADMIN([
            UserService.RoleEnum.ROLE_SUPERADMIN,
            UserService.RoleEnum.ROLE_ADMIN,
            UserService.RoleEnum.ROLE_RECEPTION,
            UserService.RoleEnum.ROLE_HOUSEKEEPING
        ]),
        ROLEGROUP_ADMIN([UserService.RoleEnum.ROLE_ADMIN]),
        ROLEGROUP_RECEPTION([UserService.RoleEnum.ROLE_RECEPTION]),
        ROLEGROUP_HOUSEKEEPING([UserService.RoleEnum.ROLE_HOUSEKEEPING]),
        ;

        private List<RoleEnum> roles

        List<RoleEnum> getRoles() {
            return roles
        }

        RoleGroupEnum(List roles) {
            this.roles=roles;
        }
    }


    def serviceMethod() {
        RoleGroupEnum superadmin=RoleGroupEnum.ROLEGROUP_SUPERADMIN;  
       // Throws groovy.lang.GroovyRuntimeException
    }
}

调用serviceMethod()会引发以下异常:

Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: UserService$RoleGroupEnum(java.lang.String, java.lang.Integer, UserService$RoleEnum)
    at groovy.lang.MetaClassImpl.selectConstructorAndTransformArguments1(MetaClassImpl.java:1621)
    at groovy.lang.MetaClassImpl.selectConstructorAndTransformArguments(MetaClassImpl.java:1537)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.selectConstructorAndTransformArguments(ScriptBytecodeAdapter.java:238)
    at UserService$RoleGroupEnum.$INIT(UserService.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:222)
    at UserService$RoleGroupEnum.<clinit>(UserService.groovy:18)

我不知道这个签名来自哪里:UserService$RoleGroupEnum(java.lang.String, java.lang.Integer, UserService$RoleEnum)

出于好奇,我添加了以下构造函数:

    RoleGroupEnum(String wtf1, Integer wtf2, RoleEnum wtf3) {
        log.debug("WTF");
    }

我使用相同的签名获得相同的异常。 有人可以解释一下发生了什么吗?

0 个答案:

没有答案