AntiPattern

Annotation Constant Mismatch

annotation-constant-mismatch

annotation fields must be compile-time constants — a Java annotation. Tension: you can’t put a runtime value directly into a Java annotation. | the compiler complains that "Attribute value must be constant" — On setting the attribute dynamicValue to value which is read from the YAML file. Tension: I know it expects a compile time constant value, but is there any way to insert a runtime value here? | A common approach is to put a placeholder string in the annotation — using Spring’s Environment. Tension: This only works if the code processing the annotation has access to the YAML or properties. Outcome: resolve it at runtime using Spring’s Environment.