Spring Expression Language(SpEL)
The Spring Expression Language (“SpEL” for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. The language syntax is similar to Unified EL but offers additional features, most notably method invocation and basic string templating functionality.
详情参阅:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions
模式配置(SpelCompilerMode):解释执行模式(OFF)、编译模式(IMMEDIATE)、混合模式(MIXED)
使用示例:
Bean中使用(Expressions in Bean Definitions):
1 //1 2 public class FieldValueTestBean { 3 4 @Value("#{ systemProperties['user.region'] }") 5 private String defaultLocale; 6 7 public void setDefaultLocale(String defaultLocale) { 8 this.defaultLocale = defaultLocale; 9 } 10 11 public String getDefaultLocale() { 12 return this.defaultLocale; 13 } 14 } 15 16 17 //2 18 public class PropertyValueTestBean { 19 20 private String defaultLocale; 21 22 @Value("#{ systemProperties['user.region'] }") 23 public void setDefaultLocale(String defaultLocale) { 24 this.defaultLocale = defaultLocale; 25 } 26 27 public String getDefaultLocale() { 28 return this.defaultLocale; 29 } 30 } 31 32 //3 33 public class SimpleMovieLister { 34 35 private MovieFinder movieFinder; 36 private String defaultLocale; 37 38 @Autowired 39 public void configure(MovieFinder movieFinder, 40 @Value("#{ systemProperties['user.region'] }") String defaultLocale) { 41 this.movieFinder = movieFinder; 42 this.defaultLocale = defaultLocale; 43 } 44 45 // ... 46 }