Spring @Value Annotation Example
In this section we will learn about @Value Annotation. Note This annotation can be used for injecting values into fields in Spring-managed beans, and it can be applied at the field or constructor/method parameter level. It 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. Let’s look at some of the examples of using @Value annotation. 1. Set Default/Static Value We can assign a class member variable with default/static value using @Value annotation. // Set static string value @Value ( "Hi, This is a static message." ) private String staticMessage ; // Set default boolean value @Value ( "true" ) private boolean booleanValue ; // Set static integer value @Value ( "234" ) private int integerValue ; 2. Get Value from Properties File @Value can be used to read values from the properties file. 2.1 Ge