Skip to content

Spring Framework Blog

Menu
  • Home
  • Spring
  • Spring Boot
  • About
Menu

SpEL and Value

Posted on June 2, 2024June 18, 2024 by Armando Marques

Table of Contents

Toggle
  • Spring EL
  • @Value

Spring EL

Accessing properties:

$ – value
# – expression/execution

Value
- @Value(“${bean.message}”)

System environment variable
- @Value(“#{systemEnvironment[‘SOME_ENV_VARIABLE’]}”)

It casts to the required type:

@Value(“${daily.limit}”) 
int maxTransferPerDay

@Value(“#{environment[‘daily.limit’]}”)
int maxTransferPerDay;

But values are handled as String:

@Value(“#{new Integer(environment[‘daily.limit’]) * 2 }”) -> OK
@Value (“#{new java.net.URI(environment[‘home.page’]).host}”) -> OK
@Value (“#{daily.limit * 2}”}) -> not OK

Default values:

@Value(“${daily.limit:1000}”)
@Value(“#{environment[‘daily.limit’]?:1000}”)

https://www.baeldung.com/spring-expression-language

@Value

This annotation can be placed in:

Constructor

@Autowired
public TransferServiceImpl(@Value("${daily.limit}") int max){
...
}

Method

@Autowired
public int setDailyLimit(@Value("${daily.limit}") int max){
...
}

Value

@Value("${daily.limit}")
int max;

https://www.baeldung.com/spring-expression-language

  • Spring
  • Documentation
  • References
  • Toc
  • Books
  • Certification
  • AOP
  • Config
  • Java
  • Java core
  • JDBC
  • JPA
  • Rest
  • Security
  • Spring
  • Spring Boot
  • Spring Core
  • Spring Data
  • Spring MVC
  • Spring Rest
  • Spring Security
  • Tests
  • Transactions
  • Uncategorized

Recent Posts

  • Spring Annotations
  • Java Tests
  • Java operators
  • Java versions
  • Java Oracle Licenses
  • Configuration properties
  • MockMvc
  • Spring Security III
  • MVC Controller Method Params
  • JPA Methods
  • Transaction propagation and isolation
  • Spring JDBC
  • Spring Boot Auto-Configuration
  • Spring Resource interface
  • JSR 330 Standard Annotations
  • Spring Aware Interfaces
  • Spring Transactions
  • Spring Boot Core
  • MVC Rest
  • Spring Boot JPA
©2025 Spring Framework Blog | Built using WordPress and Responsive Blogily theme by Superb