This discussion is archived
2 Replies Latest reply: Mar 25, 2011 1:42 AM by 802316 RSS

Can I Use Properties File Value in Annotation?

michelle Newbie
Currently Being Moderated
Hi Experts,

I have a java class using an annotation for a url, e.g.,


I can't hard-code the url in the java code during deployment to appserver. I'm wondering if there's a way to use properties file value in this annotation, so that the url can be pickup up during runtime?

  • 1. Re: Can I Use Properties File Value in Annotation?
    asrivast Newbie
    Currently Being Moderated
    Did you ever get its answer? I am looking for the same but it seems the annotation value has to be a constant and a variable cannot be used unless it is a constant.

    private final static val = 1000;

    @Anno(value=val) - will work but

    private final static val = Integer.valueOf(bundle.getString("val"));

    @Anno(value=val) - will not!

    But if there is a way I would be very interested.
  • 2. Re: Can I Use Properties File Value in Annotation?
    802316 Pro
    Currently Being Moderated
    annotation values have to be constant. The only way around this if your library supports lookups to get the final value.
    String val = "/my-directory/my-file";
    The value is still constant, and the library needs to know it could get the true value from a field.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points