Merhaba arkadaşlar, bu yazımda Collections Injection konusunu anlatacağım. 4 adet collection tipinde inject işlemi yapılır. Bunlar:
- List – <list/>
- Set – <set/>
- Map – <map/>
- Properties – <props/>
Şimdi örnek üzerinden anlatalım:
CollectionsClass.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public class CollectionsClass { private List<String>myList; private Map<Integer, String>myMap; private Set<String>mySet; public List<String> getMyList() { System.out.println("MyList=> "+myList); return myList; } public void setMyList(List<String> myList) { this.myList = myList; } public Map<Integer, String> getMyMap() { System.out.println("MyMap=> "+myMap); return myMap; } public void setMyMap(Map<Integer, String> myMap) { this.myMap = myMap; } public Set<String> getMySet() { System.out.println("MySet=> "+mySet); return mySet; } public void setMySet(Set<String> mySet) { this.mySet = mySet; } } |
Test.java
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Test { public static void main(String[] args) { ApplicationContext applicationContext=new ClassPathXmlApplicationContext("_005_application.xml"); CollectionsClass collectionsClass=applicationContext.getBean("collectionsClass",CollectionsClass.class); collectionsClass.getMyList(); collectionsClass.getMySet(); collectionsClass.getMyMap(); ((ClassPathXmlApplicationContext)applicationContext).close(); } } |
Application.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<bean id="collectionsClass" class="_005_collection_injection_xml.CollectionsClass"> <property name="myList"> <list> <value>Furkan</value> <value>Emre</value> <value>Osman</value> </list> </property> <property name="mySet"> <set> <value>İstanbul</value> <value>Ankara</value> <value>Çankırı</value> </set> </property> <property name="myMap"> <map> <entry key="34" value="İstanbul" /> <entry key="18" value="Çankırı" /> <entry key="25" value="Erzurum" /> </map> </property> </bean> |
Bu yazıyı burada bitiriyorum diğer yazılarımda görüşmek üzere….