【问题标题】:How to pass param value dynamically to custom annotation如何将参数值动态传递给自定义注释
【发布时间】:2022-11-25 17:38:43
【问题描述】:

我正在使用创建了以下自定义注释的库。

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@DependsOn({"springBeanUtils"})
public @interface PartyCacheable {
    boolean enable() default false;
}

下面是我使用上面注释的 sn-p

@PartyCacheable(enable = false)       // this value needs to be toggled from property value 
public class PartyProcessing {

// some implementation

}

有没有办法根据 application.properties 文件用 true 和 false 切换 PartyCacheable 注释?

party.cache.enable=true

【问题讨论】:

    标签: java spring spring-boot properties annotations


    【解决方案1】:

    不,你不能使用带有属性的注释。注释必须与常量值一起使用。

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多