第一种:@Configuration + @Bean
@Configuration
public class AppConfig {
@Bean
public CollectionBean collectionBean() {
CollectionBean bean = new CollectionBean();
List<String> list = new ArrayList<>();
list.add("Item1");
list.add("Item2");
list.add("Item3");
bean.setStringList(list);
Set<String> set = new HashSet<>();
set.add("ItemA");
set.add("ItemB");
set.add("ItemC");
bean.setStringSet(set);
Map<String, String> map = new HashMap<>();
map.put("Key1", "Value1");
map.put("Key2", "Value2");
map.put("Key3", "Value3");
bean.setStringMap(map);
return bean;
}
}
第二种:@Configuration + @ImportResource({“classpath:customConfig1.xml”}) + classpath:customConfig1.xml
@Configuration
@ImportResource({
"classpath:customConfig1.xml"})
public class AppConfig {
}
xml配置文件 customConfig1.xml
<beans xmlns="http://www.springframework.org/schema/beans