list inject test
This commit is contained in:
parent
4d800396b8
commit
c7cd7d0744
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue