Spring Expression Language (SpEL)

Spring Framework (24 Part Series)

1 Spring Configuration
2 External Properties in Spring
20 more parts…
3 Profiles in Spring
4 Spring Expression Language (SpEL)
5 How Spring implements Singleton Beans
6 Converting explicit into implicit configuration in Spring
7 Autowiring in Spring
8 Lazy Beans in Spring
9 @PostConstruct and @PreDestroy in Spring
10 Stereotype and Meta Annotations in Spring
11 Spring’s FactoryBean Interface
12 The Spring Bean Lifecycle
13 Spring AOP
14 Caching in Spring
15 Spring JDBC
16 Spring Transaction Management
17 JPA with Spring
18 JPA with Spring Boot
19 Spring Web MVC
20 Spring Boot for war
21 Spring MVC REST
22 Reactive Spring Applications
23 Spring Security
24 Spring Injection Types

You can use it as implicit references defining an attribute or an argument in a method:

@Value("#{ systemProperties['user.region'] }") String defaultLocale;

Enter fullscreen mode Exit fullscreen mode

SpEL can access Spring beans:

@Value("#{beanId.method}") BeanType param;

Enter fullscreen mode Exit fullscreen mode

SpEL can access properties as Strings (casting may be needed):

@Value("${property1}") int property1;
@Value("#{environment['property2']}") int property2;
@Value("#{new Integer(environment['property3'])*2}") int property3;

Enter fullscreen mode Exit fullscreen mode

If undefined use : or ?: for SpEL to assign a default value:

@Value("${property1 : 1}") int property1;
@Value("#{environment['property2'] ?: 1}") int property2;

Enter fullscreen mode Exit fullscreen mode

原文链接:Spring Expression Language (SpEL)

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容