Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par محمد حسام الدين حسن صدقى , Senior Functional Consultant , Egabi Fsi
Date de publication: 2016/12/03
MOHAMMAD Sahwan
par MOHAMMAD Sahwan , It Solution Expert , Siemens Eenrgy

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

<bean>

<property list="">

<llist>

</list>

</bean>

Mahesh Asutkar
par 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
par charan teegala , Product Engineer , EZDI

By Using Spring IOC Dependency Injection

<property ------->

<list -->

---------

</list>

</property>

Arka Dey
par 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
par 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
par 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
par Ankit Sodani , Manager , Ultratech Cement LTD

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

 

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

Add Collection dependency injection in the spring servlet.xml

More Questions Like This