Results 1 to 3 of 3

Thread: BeanFactory and Configuring/Defining Only Superclasses

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default BeanFactory and Configuring/Defining Only Superclasses

    Hello,

    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.

    Thanks!
    Seth

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    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.

    Seth

Similar Threads

  1. BeanFactory lifecycle?
    By swruch in forum Container
    Replies: 4
    Last Post: Feb 23rd, 2006, 12:57 PM
  2. MDB and BeanFactory
    By vichandoko in forum Container
    Replies: 1
    Last Post: Sep 14th, 2005, 01:06 AM
  3. BeanFactory, FactoryBean and &
    By cherrick in forum Architecture
    Replies: 1
    Last Post: Aug 23rd, 2005, 07:42 PM
  4. JNDI BeanFactory lookup
    By edalquist in forum Container
    Replies: 4
    Last Post: Dec 16th, 2004, 02:18 PM
  5. Looking up beanfactory
    By f_kasper in forum Container
    Replies: 5
    Last Post: Sep 24th, 2004, 04:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •