Creating inline list in SpEL

In this post under Spring SpEL, I will show with example how to create and access inlist line.

Below is the complete class file reference.

1  package spel.package5;
2  
3  import org.springframework.beans.factory.annotation.Value;
4  import org.springframework.context.ApplicationContext;
5  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
6  import org.springframework.context.annotation.ComponentScan;
7  import org.springframework.stereotype.Component;
8  
9  import java.util.List;
10 
11 @Configuration
12 @ComponentScan(basePackages = "spel.package5")
13 public class Example5 {
14     @Value("#{{1,2,3,4,5}}")
15     private List<Integer> list;
16 
17     public static void main(String[] args) {
18         ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Example5.class);
19         Example5 example5 = applicationContext.getBean(Example5.class);
20         System.out.println(example5.list.size());
21     }
22 }

In the above code at line 14, we create an inline list.

In this way we can create an inline list using SpEL.

Leave a comment