I have an entity/model with discriminator formula and now I'm assigning a discriminator formula like the following sample,
@Entity
@DiscriminatorFormula("type")
class Student {
// code
}
In the same case, how can I assign discriminator value from application.properties
in Spring Boot?
You can use @Value("${property-name}") from the application. properties if your class is annotated with @Configuration or @Component . You can make use of static method to get the value of the key passed as the parameter.
Spring get value from system property. You can set the system property on the Java command line using the -Dpropertyname=value syntax or at runtime using System. setProperty function. To inject the value from the system property, annotate your field using the @Value annotation with SpEL expression as below.
Spring @Value annotation is used to assign default values to variables and method arguments. We can read spring environment variables as well as system variables using @Value annotation. Spring @Value annotation also supports SpEL.
The expression in the class level annotation should be a constant, i.e., final
and static
. What you are trying to achieve is not possible. The best you can do is read it from a constant file rather than application.properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With