Andreas Hartmann wrote:
Hi Grzegorz, hi Reinhard,

thanks for your replies!

Reinhard Pötz schrieb:
Grzegorz Kossakowski wrote:
Andreas Hartmann pisze:

[…]

Andreas, have a look at "bean-maps" which are provided by the Spring
Configurator. You could have your validators implement a particular
interface and then you can collect them by using a bean-map. The you can
implement a validator servlet-service that uses this bean-map and does
the validation. Of course the last step is only necessary if you need to
get access to the validator services by using the servlet protocol.

I found the documentation on bean maps and Grzegorz' blog entry, but I'm not quite sure if I understand the concept correctly. At a first glance it looks very similar to Avalon selectors.

E.g. if I instantiate two beans like this:

  <bean name="myproject.Service/foo" … />
  <bean name="myproject.Service/bar" … />

Is this sufficient for accessing the beans via the bean map?

  <bean name="my-client-bean">
    <property name="services">
      <configurator:bean-map type="myproject.Service">
    </property>
  </bean>

  Service foo = (Service) services.get("foo")

the beans should be named :
<bean name="foo" … />
<bean name="bar" … />


the matching is done by type - no need to have it in bean name.

If you want to retain your naming and still query by "foo", do this:

<bean name="myproject.Service/foo" … />
<bean name="myproject.Service/bar" … />

<bean name="my-client-bean">
  <property name="services">
    <configurator:bean-map type="myproject.Service" strip-prefix="true">
  </property>
</bean>

If this is correct, it would solve the problem of registering the beans at runtime (IIUC this is the major purpose of the bean map?).

exactly

For my understanding: Would this be equivalent to getting the bean directly from the app context?

  Service foo = (…) context.getBean(Service.class.getName() + "/foo")

Yes with one big GOTCHA: your beans should be singletons. I'll leave the explanation why as an exercise :)

--
Leszek Gawron                         http://www.mobilebox.pl/krs.html
CTO at MobileBox Ltd.

Reply via email to