list inject test

This commit is contained in:
mherbaghinyan 2018-05-18 16:10:02 +04:00
parent 4d800396b8
commit c7cd7d0744
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.baeldung.collection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.List;
@Configuration
public class CollectionConfig {
@Bean
public CollectionsBean getCollectionsBean() {
return new CollectionsBean();
}
@Bean
public List<String> nameList(){
return Arrays.asList("John", "Adam", "Harry");
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.collection;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* Created by Gebruiker on 5/18/2018.
*/
public class CollectionInjectionDemo {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(CollectionConfig.class);
CollectionsBean collectionsBean = (CollectionsBean)context.getBean(CollectionsBean.class);
collectionsBean.printNameList();
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.collection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* Created by Gebruiker on 5/18/2018.
*/
public class CollectionsBean {
@Autowired
private List<String> nameList;
public void printNameList() {
System.out.println(nameList);
}
}