属性值必须在SwaggerConfig中是一个常量

huangapple go评论57阅读模式
英文:

Attribute value must be a constant in SwaggerConfig

问题

我已经为一个类配置了Swagger,但在使用常量创建基本路径时出现错误,

public static final String paymentControllerBasePath = "cx/payment/v1";
public static final String payoutControllerBasePath = "cx/payment/v1";

如果我尝试在类中导入它们,如下所示,

@Api(tags = { paymentControllerBasePath }, value = "payment functionality", produces = "application/json")

上面一行中的tags值在IntelliJ中显示错误,

Attribute value must be constant

嗯,它确实是一个常量。有人能帮我解决这个错误吗?

英文:

I have swagger configured for a class and the error for creating base path using constants,

public static final String paymentControllerBasePath = "cx/payment/v1"
public static final String payoutControllerBasePath = "cx/payment/v1"

If I try to import them into a class, like,
@Api(tags = { paymentControllerBasePath }, value = "payment functionality", produces = "application/json")

The tags value in the above line shows an error in IntelliJ saying

Attribute value must be constant

Well, it is a constant. Can anyone help me mitigate this error?

答案1

得分: 1

请使用字符串字面值。注解不接受变量或常量变量。
编译时常量仅限于原始数据类型。并且注解不接受运行时变量或常量。

英文:

Please use string literals. Annotations don’t accept variables or constant variables.
Compile time constants are primitive data types only. And annotations don’t accept runtime variables or constants.

huangapple
  • 本文由 发表于 2020年8月10日 01:34:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63329406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定