问题
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