Close

Spring Framework - Spring Expression Language Examples

Spring Framework 

Using Spring Expression Language with @Value annotation.

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

@Component
public class MyBean {
@Value("#{systemProperties['user.home']}")
private String userHome;

@Value("#{T(java.lang.Math).random()*1000}")
private int randomNumber;

@PostConstruct
public void postInit() {
System.out.println("System userHome: " + userHome);
System.out.println("Random number: " + randomNumber);
}
}
Original Post




See Also