无法从bean中检索Object的实例

时间:2015-03-30 10:51:09

标签: java spring

我已将shipmentProperties.xml文件定义为:

<bean id = "shipmentProperties" class = "com.amazon.tfs.utils.Record" scope="prototype">
    <constructor-arg type = "java.lang.String" value = "shipmentProperties" />
    <property name = "schema">
        <map>
            <entry key = "shipmentProperty" value = "com.abc.xyz.data.types.ShipmentProperty" />
        </map>
    </property>
</bean>

在其他地方,我尝试使用

检索它
myproperties = (Record) ApplicationBean.staticGetNonNullable("shipmentProperties");

if (myproperties == null) {
    logger.info("It is pkgGTSDataCreationSstage and shipmentProperties can not be retrieved from bean");
}
ShipmentProperty prop = (ShipmentProperty) myproperties.get(shipmentProperty);

if (prop == null) {
    logger.info("Object of class shipmentProperties can not be retrieved from bean");
}

现在问题是打印的输出是无法从bean中检索到类shipmentProperties的对象。

我不明白为什么没有实例化?有人可以告诉我为什么会出现这个问题吗?

2 个答案:

答案 0 :(得分:0)

ShipmentProperty也需要标记为bean,因为shipmentProperties bean依赖于它。另外,我假设ShipmentProperty类中有getter?

答案 1 :(得分:0)

尝试

<entry key = "shipmentProperty">
    <bean class="com.abc.xyz.data.types.ShipmentProperty" />
</entry>

假设ShipmentProperty构造函数不带参数。