Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to inject List<String> values using a spring framework?

user-image
Question added by محمد حسام الدين حسن صدقى , Senior Functional Consultant , Egabi Fsi
Date Posted: 2016/12/03
MOHAMMAD Sahwan
by MOHAMMAD Sahwan , It Solution Expert , Siemens Energy

in Spring bean configuration file inside the bean write one property tag

<bean>

<property list="">

<llist>

</list>

</bean>

Mahesh Asutkar
by Mahesh Asutkar , Java Web Developer , Accenture Solution

in the spring bean we can autowired and by help of xml conf. file inject the list elements, dependency injection feature of spring need to use.

<Bean id=""  >

<property value="" />

<list>

.........

</list>

</bean>

charan teegala
by charan teegala , Product Engineer , EZDI

By Using Spring IOC Dependency Injection

<property ------->

<list -->

---------

</list>

</property>

Arka Dey
by Arka Dey , Software Engineer , Softtek India Pvt Ltd

Inside Spring configuraton file where we will use bean configuration inside bean tag.

<bean>

<list>  

<value></value>  

</list> 

</bean>

KUMAR KUNAL
by KUMAR KUNAL , Java Technical Lead, Technical Architect , D4 Insight for Ahli United Bank

xml configuration for injecting(DI) List into the spring bean.

ex - <util:list id="" value-type="java.lang.String"><value></value></util:list>

using spring dependency injection with property name of list

 

Venkata Naga Durga Prasad Grandhi
by Venkata Naga Durga Prasad Grandhi , Java Developer , Green Buds Software Technologies

<PROPERTY NAME="list">

<LIST>

<VALUE>GVO</VALUE>

<VALUE>GVP</VALUE>

</LIST>

</PROPERTY>

TO   INJECT LIST<STRING> INTO SPRING W HAV TO USE <LIST> TAG IN XML FILE WHIH IS SUB ELEMENT OF <PROPERTY> TAG AND <CONSTRUCTOR-ARG> TGA

SEE:

<PROPERTY NAME="A">

<LIST>

<VALUE>ANUJ SINGH</VALUE>

<VALUE>POOJA SINGH</VALUE>

</LIST>

</PROPERTY>

HERE PROPERTY NAME IS NAME OF LIST LIKE:LIST<STRING>A

NOW AT A[0]=ANUJ SINGH

A[1]=POOJA SINGH

list.of.strings=first,second,third took from properties file for e.g.

Then using SpEL:

 @Value("#{'${list.of.strings}'.split(',')}") 

 private List<String> list;

Ankit Sodani
by Ankit Sodani , Manager , Ultratech Cement LTD

In XML we can use <util:list id="myList" value-type="java.lang.String">

 

Dionifer Canabano
by Dionifer Canabano , Programmer / Analyst , Banco De Oro Inc. (BDO)

Add Collection dependency injection in the spring servlet.xml

More Questions Like This