in Spring



In this tutorial I will show you how to use SpEL using real life examples in the world of Knights and Swords ūüôā

Here are interfaces and implementations that are going to be used in this tutorial


Set Literal value XML

Lets see how to set literal value using p namespace

Set Literal value @Value

For this we need to use annotation @Value.

NOTE: It is important to add  <context:annotation-config /> in your XML so that @Value annotation works.

Set other bean value XML

In this example I will show you how to set property of your bean using value from property of other bean.

Set other bean value @Value

Wire beans together using SpEL

Lets initialize knight bean using SpEL and set his weapon this way

Use Static Methods

You can use static methods like this, just use special T operator can be used to specify an instance of java.lang.Class and invoke your static method.


I hope that this examples will come handy.


Write a Comment