user1895160
user1895160

Reputation: 3

Create bean by calling another bean's method

I am not familiar with Java or Spring. I have a bean injected which is a Map. I want to inject another bean which will be Set of all the keys in Map.

`

<util:map id="servers">
   <entry key="www.google.com" value="google" />
   <entry key="www.amazon.com" value="amazon" />
   <entry key="www.apple.com" value="apple" />
</util:map>

`

I want use this bean to create a Set by calling Map.keySet() method. `

<bean id="serverHosts" >
    <value></value>
</bean>

` How to I initialize this bean?

Upvotes: 0

Views: 1037

Answers (1)

Jose Luis Martin
Jose Luis Martin

Reputation: 10709

Try with

<bean id="serverHosts" factory-method="keySet" factory-bean="servers" />

Upvotes: 2

Related Questions