Is it possible to access string-indexed getter with Spring XML?

喜夏-厌秋 提交于 2019-12-13 16:01:48

问题


Is there a notion of "string-indexed" getters in spring context setup XML language? Suppose I have Person getter with the following prototype:

class Person {
   Person getRelative(String relativeName);
   ...
}

Can I access it with something like

<bean id="Bob" class="Person"/>

<bean id="Barnyard" class="Company">
   <property name="owner" ref="Bob.relative.father"/>
</bean>

saying that Bob's father is the owner of Barnyard company.

The Company prototype is like follows:

class Company {
   Person getOwner();
   void setOwner(Person value);
   ...
}

回答1:


You can use Spring-El for this:

<bean id="Barnyard" class="Company">
   <property name="owner" value="#{Bob.getRelative('father')"/>
</bean>


来源:https://stackoverflow.com/questions/12823332/is-it-possible-to-access-string-indexed-getter-with-spring-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!