简体   繁体   English

如何将参数值动态传递给自定义注释

[英]How to pass param value dynamically to custom annotation

I am using a library which has below custom annotation created.我正在使用创建了以下自定义注释的库。

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

Below is the snippet where I am using above annotation下面是我使用上面注释的片段

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

// some implementation

}

Is there a way to toggle PartyCacheable annotation with true and false based from the application.properties file?有没有办法根据 application.properties 文件用 true 和 false 切换 PartyCacheable 注释?

party.cache.enable=true

No you can not use annotations with properties.不,你不能使用带有属性的注释。 Annotations have to be used with constant values.注释必须与常量值一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM