gpt4 book ai didi

java - 将制表符作为注释参数传递 : "attribute value must be constant"

转载 作者:行者123 更新时间:2023-12-01 18:16:38 26 4
gpt4 key购买 nike

我有一个包含多个常量的类,我想返回除一个常量之外的所有常量,以便进行一些测试。我做了一个简单的方法,但当我在注释中使用它时,它返回错误“属性值必须是常量”。

public final class RolesConstants {

public static final String APP_SYSTEM = "APP_SYSTEM";
public static final String APP_CLIENT = "APP_CLIENT";
public static final String APP_PROFESSIONAL = "APP_PROFESSIONAL";
public static final String APP_ADMIN = "APP_ADMIN";
public static final String PRO_ADMIN = "PRO_ADMIN";
public static final String PRO_ADD_BOOKING = "PRO_ADD_BOOKING";
public static final String PRO_EDIT_BOOKING = "PRO_EDIT_BOOKING";
...

public static String[] allRolesButAPP_SYSTEM() {
return new String[]{ APP_CLIENT, APP_PROFESSIONAL, ... };
}
}


import org.springframework.security.test.context.support.WithMockUser;

public class ProfessionalResourceIT {

@WithMockUser(roles = {RolesConstants.allRolesButAPP_SYSTEM()})
public void cannotGetIfNotSystem(){
assertThat(...);
}
}

attribute value must be constant

最佳答案

你能尝试这样的事情吗

import org.springframework.security.test.context.support.WithMockUser;

public class ProfessionalResourceIT {

@WithMockUser(roles = {RolesConstants.APP_SYSTEM, RolesConstants.APP_CLIENT, so on})
public void cannotGetIfNotSystem(){
assertThat(...);
}
}

关于java - 将制表符作为注释参数传递 : "attribute value must be constant",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60351432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com