Announcement Announcement Module
Collapse
No announcement yet.
newbie question: bean re-usage Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      Comment

      Working...
      X