Fill the value of the annotation parameter with the value from the properties file

I am developing a simple web application in Java EE. I use annotations for servlets, and I would like to populate the annotation parameters with the value from the properties file, but I do not know how to do this. I would like to do something like this:

// My Servlet    
@WebServlet(urlPatterns="${key.value1}")
    public class HomeServlet extends MyCustomServlet
    {
      ...
    }

# My properties files
key.value1=/home

Is it possible? If so, what is the solution?

Thanks.

+4
source share
1 answer

It's impossible. The values ​​you give the annotation attributes must be constants. They cannot be changed after compiling the code. From Java Language Specification

, , : , String, Class, , (§8.9), (§10), .

, , ( , , Servlet), .

URL.

+4

Source: https://habr.com/ru/post/1524730/


All Articles