Results 1 to 3 of 3

Thread: newbie question: bean re-usage

  1. #1
    Join Date
    Sep 2005
    Posts
    2

    Default newbie question: bean re-usage

    Hi,

    I am just starting in spring and need to know if the following is possible. Here is the situation. I have several components to initialize each of which can be in any of several states. Can I define beans that consume these , setting properties on the fly. So for instance

    <bean id="comp0" class="...">
    <!-- bunch of config stuff -->
    </bean>

    <bean id="comp1" class="...">
    <!-- bunch of config stuff -->
    </bean>

    <bean id="consumer" class="...">
    <!-- *some* properties set, but not which component!! -->
    </bean>

    <!-- later in some context set which component the consumer class uses -->

    I know this is probably really easy, but I just don't seem to see this in the documentation. Since this will be repeated with several different types of components, this would lead to a huge number of possible configurations if I have to explicitly set each of these in the beans. I just want to define my dozen or so beans and then be able to use the appropriate configuration later. If this is goofy, is there a better way of doing this in Spring?

    Thanks!

    jjg

  2. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    When you write:
    Code:
    <!-- later in some context set which component the consumer class uses -->
    Do you mean programmatically, in the same bean definition file, another bean definition file, etc?

    One declaritive way is to use child beans. You can define an abstract parentConsumer that gets its properties set. Then the actual component bean, a child of the parentConsumer just has to add the actual dependent components. The advantage is that the "noise' of properties is hidden away and multiple child consumers can reuse or override the details. There is no need for an actual parent class, this is all within the bean definition schema instance.


    J. Betancourt

  3. #3
    Join Date
    Sep 2005
    Posts
    2

    Default

    In the same bean file. I imagine having several different contexts where different components are set for the various consumers. So is it possible to set properties at times other than in the initial declaration of a bean?

    Thanks!

    jjg

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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