大佬教程收集整理的这篇文章主要介绍了在spring如何为带有父级的xml中定义的bean选择构造函数?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
从Spring 文档中,
我找到以下答案,该答案解释了选择构造函数时的弹簧行为。
参考
从父级继承时,构造函数参数将合并(与合并属性集合相同)。在您的情况下,合并子Bean构造函数参数后,将
<constructor-arg value="23" type="int"/>
<constructor-arg value="10" type="int"/>
<constructor-arg value="Ringing" />
@H_618_12@
对于模棱两可的方案,请使用索引或构造函数参数名称。
我正在使用Spring 3.1.0。我试图了解spring读取其xml文件的方式。我试图了解spring如何处理bean定义中的歧义条件。
例如
package com.anshbansal.alarm2;
public class Alarm {
private String type;
privatE int volume;
privatE int hour;
public Alarm() {
}
public Alarm(String type,int volume,int hour) {
this.type = type;
this.volume = volume;
this.hour = hour;
}
public Alarm(String type,int volumE) {
this.type = type;
this.volume = volume;
}
public Alarm(int volume,String typE) {
this.type = type;
this.volume = volume;
}
public void setType(String typE) {
this.type = type;
}
public void setVolume(int volumE) {
this.volume = volume;
}
public void setHour(int hour) {
this.hour = hour;
}
@Override
public String toString() {
return "Alarm{" +
"type='" + type + '\'' +
",volume=" + volume +
",hour=" + hour +
'}';
}
}
@H_618_12@
我的spring xml文件alarm2.xml@H_618_12@如下。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/scheR_825_11845@a/beans"
xmlns:xsi="http://www.w3.org/2001/XMLscheR_825_11845@a-instance"
xsi:scheR_825_11845@aLOCATIOn="http://www.springframework.org/scheR_825_11845@a/beans http://www.springframework.org/scheR_825_11845@a/beans/spring-beans.xsd">
<bean id="propertyRandom" abstract="true">
<constructor-arg value="23" type="int"/>
</bean>
<bean id="alarm1" class="com.anshbansal.alarm2.Alarm" parent="propertyRandom">
<constructor-arg value="10" type="int"/>
<constructor-arg value="Ringing" />
</bean>
</beans>
@H_618_12@
存在歧义,因为尚不清楚哪些int@H_618_12@会大量出现,哪些会花费数小时。如果我打印得到以下内容
Alarm{type='Ringing',volume=23,hour=10}
@H_618_12@
那么spring如何读取xml文件来解析要调用的构造函数?首先是父母,然后是豆?它记录在某处吗?
我知道可以使用诸如指定index@H_618_12@和
name@H_618_12@作为属性之类的方法,但我也应该了解如何处理这种模棱两可的情况。这就是为什么我要问这个。
以上是大佬教程为你收集整理的在spring如何为带有父级的xml中定义的bean选择构造函数?全部内容,希望文章能够帮你解决在spring如何为带有父级的xml中定义的bean选择构造函数?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。