Announcement Announcement Module
No announcement yet.
BeanFactory and Configuring/Defining Only Superclasses Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanFactory and Configuring/Defining Only Superclasses


    I'd like to define just a superclass and its dependencies in my applicationContext.xml. I'd then like to instantiate a subclass, and then ask my BeanFactory (or the like) to wire it up for me.

    I know this is an odd request. I'm integrating the SpringHibernateInterceptor to wire up beans for Hibernate. I have many subclasses defined, but all have the same wiring. Instead of defining a prototype for each subclass, I'd like to define a prototype for the superclass, and define it's dependencies.

    Then, in the SpringHibernateInterceptor, I would somehow check if the BeanFactory knows how to wire up the subclass for me.

    There might be some way to ask the BeanFactory to wire up an existing bean, by matching its class. I doubt it, but I thought I'd ask.

    It's not too big of a deal, but if we can avoid defining one prototype per subclass (we have lots) then all the better.


  • #2
    It's not quite what you are asking for, but if you were to define an abstract parent bean with all the properties set, then for each child bean the definition would be just a one-liner:

    <bean id="myChild" parent="theTemplate" class="a.b.c.d.MyChildClass"/>

    Child beans are defined in the manual, in the beans chapter.


    • #3
      Thanks Colin!

      That's what I ended up doing. I have about 15 subclasses, which isn't too big of a deal, but was a lot of XML. Especially when I combined it with it with the SpringHibernateInterceptor. A lot of typing, but it seems to be working!

      Would still be interesting to have functionality to request the wiring of a bean that you already have instantiated.