java - How to customize the SpEL parser in Spring? -
spel excellent feature provided spring, sometimes, little tedious use spel call class constructors, example
<bean id="plainpojo" class="mypackage.pojo"> <property name="date" value="#{new java.util.date()}"/> </bean>
in order initiate date
instance, have include fully-qualified name of date
class. there way can define customize spel parser don't have write fully-qualified name of class want use?
by way, ok write spel this:
<bean id="plainpojo" class="mypackage.pojo"> <property name="name" value="#{new string('myname')}"/> </bean>
the string class in java.lang package, think default spel parser spring framework used has include path java.lang
.
when using spel programmatically, can inject standardtypelocator
evaluation context, after adding packages standardtypelocator
using registerimport()
. (that's how when using spel in spring integration flows). make more convenient when using custom classes in spel expressions.
we use technique in twitter endpoints.
same thing when using custom functions - have registered evaluation context.
you can customize evaluation context used when wiring beans (#{...}
) injecting custom beanexpressionresolver
application context's bean factory. subclass standardbeanexpressionresolver
, override customizeevaluationcontext()
before refresh()
ing context.
Comments
Post a Comment