Spring Class_04.2020_CORE_SpEL Flashcards
What is SpEL?
Spring expression language
What can SpEL expression can be used for?
defining BeanDefinitions
What is syntax to define SpEL expression?
#{} ${spring.version} (in maven)
Bean reference using SpEL
@Value(«#{countryBean}»)
private Country country;
(используется id из application-context.xml)
Method invocation using SpEL
Value = «#{countryBean.toString()}»
Operators using SpEL
Name = «equalTest» Value = «#{countryBean == 100}»
return boolean and set it in field with name «equalTest»
How to use regex with spell?
use word ‘matches’
#{(‘100’ matches ‘\d+’)}
What does ExpressionParser do?
allows to get value of bean fields
What is the context used by ExpressionParser?
SEC
StandarsEvaluationContext
What is used as parameter for parseExpresion() method?
name of field
What is used as parameter for getValue() method of ExcpressionParser?
instance of SEC (StandarsEvaluationContext) and type of field (ex. String.class)
Example of expression parser using
Bank bank = new Bank(«Alfa bank»); StandarsEvaluationContext bankContext = new StandarsEvaluationContext(bank); String bankName = parser.parseExpression(«name»).getValue(bankContext, String.class);