Introduction:
In this article, we focus on the configuration file beans.xml for IoC purpose.
Focusing on initialize beans whose property are collection types.
Including <list/> <set/> <map/> and <props/> elements corrosponding to List, Set, Map and Properties in JAVA.
1. Four common collection types
1) <list>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="student" class="edu.xmu.domain.Student"> <property name="scores"> <list> <value>123</value> <value>133</value> <value>132</value> </list> </property> <property name="addresses"> <list> <bean class="edu.xmu.domain.Address"> <property name="country" value="China"></property> </bean> <bean class="edu.xmu.domain.Address"> <property name="country" value="Canada"></property> </bean> <bean class="edu.xmu.domain.Address"> <property name="country" value="America"></property> </bean> <bean class="edu.xmu.domain.Address"> <property name="country" value="Austrilia"></property> </bean> </list> </property> </bean> </beans>
2) <map>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="student" class="edu.xmu.domain.Student"> <property name="addressMap"> <map> <entry key="homeAddress" value-ref="homeAddress"> </entry> <entry key="workAddress" value-ref="workAddress"> </entry> </map> </property> <property name="scoreMap"> <map> <entry key="english" value="135"></entry> <entry key="math" value="145"></entry> <entry key="chinese" value="118"></entry> </map> </property> </bean> <bean id="homeAddress" class="edu.xmu.domain.Address"> <property name="country" value="china"> </property> </bean> <bean id="workAddress" class="edu.xmu.domain.Address"> <property name="country" value="america"> </property> </bean> </beans>
3) <set>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="student" class="edu.xmu.domain.Student"> <property name="addressSet"> <set> <ref bean="homeAddress" /> <ref bean="workAddress" /> </set> </property> <property name="scoreSet"> <set> <value>122</value> <value>123</value> <value>231</value> </set> </property> </bean> <bean id="homeAddress" class="edu.xmu.domain.Address"> <property name="country" value="china"> </property> </bean> <bean id="workAddress" class="edu.xmu.domain.Address"> <property name="country" value="america"> </property> </bean> </beans>
4) <props>
Just like previous introduction. Not usually used.
2. Inner beans introduction
<bean id="student" class="edu.xmu.domain.Student"> <!-- instead of using a reference to a target bean, simply define the target bean inline --> <property name="workAddress"> <!-- This is the inner bean --> <bean class="edu.xmu.domain.Address"> <property name="country" value="China"/> <property name="province" value="Shanghai"/> </bean> </property> </bean>
Comments:
1) A <bean/>
element inside the <property/>
or <constructor-arg/>
elements defines a so-called inner beans.
2) Inner beans are always anonymous and they are always scoped as prototypes.
相关推荐
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
It leverages the power of Spring Framework to provide dependency injection, making the code more modular and testable. Java, as the programming language, is a robust choice for developing cross-...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
少儿编程scratch项目源代码文件案例素材-直升机飞行.zip
wanjunshe_Python-Tensorflow_12888_1745868924470
健康监测_Android开发_BLE蓝牙通信_心率数据采集与存储_基于小米手环2的实时心率监测应用_支持后台长时间运行的心率记录工具_可导出SQLite数据库的心率数据分析系统_适
少儿编程scratch项目源代码文件案例素材-种花模拟器.zip
嵌入式系统开发_FreeRTOS实时操作系统_STM32F103C8T6微控制器_OLED显示屏_DHT11温湿度传感器_多任务调度_多级菜单设计_万年历算法_电子闹钟功能_参数配
基于python实现的粒子群的VRP(车辆配送路径规划)问题建模求解+源码+项目文档+算法解析,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。
scratch少儿编程逻辑思维游戏源码-猫猫粉碎.zip
scratch少儿编程逻辑思维游戏源码-蓝胡子.zip
scratch少儿编程逻辑思维游戏源码-美食大亨.zip
scratch少儿编程逻辑思维游戏源码-洛克人.zip
scratch少儿编程逻辑思维游戏源码-龙冲刺.zip
思幻个人引导页V2.2版本11月29日更新.zip
scratch少儿编程逻辑思维游戏源码-骑士风斩法.zip
移动应用开发_H5CSS3ionicng-cordovaMVVM模式_基于HTML5和CSS3技术实现多页面布局ionic指令数据绑定ui-route单页跳转调用手机
少儿编程scratch项目源代码文件案例素材-植物大战僵尸创造版 Ver. 1.0.3.zip
scratch少儿编程逻辑思维游戏源码-日落(2).zip
动态星空背景个人主页(带后台).zip