0

I have an entity class that uses @NamedStoredProcedureQuery that contains an attribute (procedureName) for the stored procedure name. The name of the stored procedure that is used for querying is different in different environments, as a result of which I want to fetch the name from the properties file (the properties file are different for different environments as well).

I saw a similar question similar question in SO where people mention that it should not be done, but is'nt this a use case? Could this be done differently without the need to access property files?

ugadi
  • 9
  • An annotation attribute must be a compile-time constant. It cannot be a dynamically loaded runtime value. So no, you can't do that. – JB Nizet Nov 19 '19 at 23:04
  • 1
    @JBNizet thank you for the response, for my own clarification purpose I wanted to put it out. But for eg. "@"Value annotation takes in the value from the properties file where we specify the property (we do not specify it as a constant). lets say app.properties file contains: factory.name.url = "https://example.com" In a class containing "@"Configuration annotation one of the class fields can be assigned a value like "@"Value("${factory.name.url}"). Is'nt it run time since its reading from the property file and then assigning it the value. – ugadi Nov 19 '19 at 23:22
  • ugadi is correct. Developers who are accustomed to running from jars might consider the property to be permanent since it is sealed into the jar, but in general, the property file can be changed. – LowKeyEnergy Nov 19 '19 at 23:25
  • NamedStoredProcedureQuery is not a Spring annotation. There is no support for Spring EL expressions in Java EE annotations that are not handled by Spring. – JB Nizet Nov 19 '19 at 23:34

1 Answers1

-2

Spring Dev Tools allows you to do this.

Read the section on Global Settings File:

https://howtodoinjava.com/spring-boot2/developer-tools-module-tutorial/

LowKeyEnergy
  • 652
  • 4
  • 11