Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing static variable in spring annotations using spel

I have a value in annotation, for which I want to assign a static variable I tried something like this

@Cacheable(value = "#com.test.App.VALUE")
 public   List  someCachableMethod() {
 }

After trying this its still same Exception : field or Property cannot be found or null

public class App {
    private static String MY_NAME = " XXXX";
        public static void main(String[] args) {
                    ExpressionParser parser = new SpelExpressionParser();
            Expression exp = parser.parseExpression("#MY_NAME)");
            String message = (String) exp.getValue();
            System.out.println("---------------->"+message);
        }

    }
like image 854
Praneeth Avatar asked Jul 31 '15 14:07

Praneeth


1 Answers

Use the T operator:

"#{T(com.test.App).VALUE}"

but make the constant public.

like image 143
Gary Russell Avatar answered Oct 24 '22 08:10

Gary Russell