相关疑难解决方法(0)

访问注释中的静态字段

我尝试在Groovy类中使用Java注释,但很难将java类的静态字段设置为参数:

注释:Id.java

package x.y.annotations;

import java.lang.annotation.ElementType;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Id {

    public Class<Adapter> adapter();

    public Class<Object> targetType();

    public String targetAttribute();

    public String onDelete();

}
Run Code Online (Sandbox Code Playgroud)

带有静态字段的java类:XPerson.java

package x.y.static.domain;

public class XPerson {

    public static String ID;

}
Run Code Online (Sandbox Code Playgroud)

还有发生问题的groovy类:Person.groovy

package x.y.domain

import x.y.annotations.Id
import x.y.static.domain.XPerson

class Person {

    @Id(adapter = Adapter, targetType = XPerson, targetAttribute = XPerson.ID, onDelete = "delete")
    long id
}
Run Code Online (Sandbox Code Playgroud)

Eclipse标记"targetAttribute = XPerson.ID"部分:

Groovy:预期'xydomain.XPerson.ID'是java.lang.String类型的内联常量,而不是@ xyannotations.Id中的属性表达式

我也尝试了"XPerson.@ ID"之类的东西,或者为ID字段定义了一个getter,但没有任何帮助.

任何提示都会很棒.

问候,迈克尔

groovy annotations

2
推荐指数
1
解决办法
3560
查看次数

Spring security 注解预计将是内联常量

当我尝试在 @Secured 注释之外定义字符串时,我在 grails 中遇到以下错误。

我收到以下错误 Role.USER' to be an inline const of type java.lang.String not a property expression in @grails.plugin.springsecurity.annotation.Secured

class Role {
    final static String USER = "ROLE_USER"
    final static String ADMIN = "ROLE_ADMIN"


    public final static String[] LOGINED_USER = [USER, ADMIN].asImmutable()

}
Run Code Online (Sandbox Code Playgroud)

下面的控制器说明了我的问题..

class MyController {

    @Secured(["permitAll"]) //Works fine
    def action1() {
    }


    @Secured(LOGINED_USER) //Doesn't work
    def action2() {
    }

    @Secured([Role.ADMIN, Role.USER]) //Doesn't work
    def action3() {
    }


    @Secured(["ROLE_ADMIN", "ROLE_USER"]) //Works fine
    def action4() {
    }
}
Run Code Online (Sandbox Code Playgroud)

grails spring-security

0
推荐指数
1
解决办法
3477
查看次数

标签 统计

annotations ×1

grails ×1

groovy ×1

spring-security ×1