标签:
1、主要配置修改就是两点,一点是xml配置文件中,另外就是bean的注入中。
<bean id="jack" class="com.test.pro.Singer"> <property name="language"> <list> <value>英文</value> <value>中文</value> <value>日文</value> </list> </property> </bean>
package com.test.pro; import java.util.List; public class Singer { private List<String> language; public List<String> getLanguage() { return language; } public void setLanguage(List<String> language) { this.language = language; } public void saying() { for(String s : language) { System.out.println("我会的语言+"+s); } } }
package com.test.pro; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext ctx=new ClassPathXmlApplicationContext("spring.xml"); Singer singer=(Singer)ctx.getBean("jack"); singer.saying(); } }
输出结果
总结一下,注入复杂的关键点,其实就是在xml配置文件property的value即可。
标签:
原文地址:http://blog.csdn.net/itbuluoge/article/details/44521155