Can i use @value annotation inside a method to read property?
void method1(){
@Value("#{AppProperties['service.name']}") String name;
-------
-------
}
accessor private for a method variable is unappropriate.
If you look at the definition of @Value annotation, it can only be placed FIELD, PARAMETER or METHOD level.
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Value {
So either you declare name as a class attribute or as a method parameter...
no :) you can use annotations to annotate classes, fields, methods and their arguments. but not in methods, since there is no way, to get method- local variables using reflection in order to process these annotations. Use @Value in your field, and read the value from your method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With