7.4.2 Compound property names

You can use compound or nested property names when you set bean properties, as long as all components of the path except the final property name are not null. Consider the following bean definition.

你可以使用复合或嵌套属性名称当你设置bean属性时,只要路径中所有组成部分除了最后的属性名外都不为空.考虑下面的bean定义.

<bean id="foo" class="foo.Bar">
    <property name="fred.bob.sammy" value="123" />
</bean>

The foo bean has a fred property, which has a bob property, which has a sammy property, and that final sammy property is being set to the value 123. In order for this to work, the fred property of foo, and the bob property of fred must not be null after the bean is constructed, or a NullPointerException is thrown.

 foo bean有一个 fred 属性, fred 有一个 bob 属性, bob 属性有一个 sammy 属性,最后的 sammy 属性的值被设置为 123.为了让它能够运行,在这个bean被构造后, foo fred 属性, fred 的 bob 属性必须不能为空,不然就会抛出 NullPointerException .

猜你喜欢

转载自blog.csdn.net/weixin_41648566/article/details/80884737