Easy learning with example program codes

Spring spel method invocation example

Spring SpEL:

The SpEL stands for Spring Expression Language. It is a powerful expression language which supports querying and manipulating an object graph at the bean creation time or run time. It is similar to other expression languages like JSP EL, OGNL, MVEL and JBoss EL etc with some additional features like method invocation and basic string templating functionality.

Spring SpEL method invocation:

Spring spel provides the facility of method invocation i.e. execute method and inject the method returned value into property.




import org.springframework.stereotype.Component;
public class StudentClass {
	public String getClassName(){
		return "MCA Final";

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
public class Student {
	private String name;	
	private String className;
	public String getName() {
		return name;
	public void setName(String name) { = name;
	public String getClassName() {
		return className;
	public void setClassName(String className) {
		this.className = className;


<beans xmlns=""
 <context:component-scan base-package="" />

import org.springframework.context.ApplicationContext;
 * Spring SPEL method invocation example.
 * @author codesjava
public class Test {
 public static void main(String args[]){	
   //Get application context object.
   ApplicationContext context = 
     new ClassPathXmlApplicationContext("applicationContext.xml");
   //Get studentBean.
   Student student = (Student) context.getBean("studentBean");
   //Print student properties.
   System.out.println("Name: "+student.getName()); 
   System.out.println("Street: "+student.getClassName()); 


Name: Jai
Street: MCA Final

Download this example.

Copyright © 2018 CodesJava Protection Status SiteMap