Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0.6
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      There should be a way to order bean initialization. Using "depends-on" is too verbose and is forcing us to explicitly bind business beans with technical beans:

      <bean name="my-technical-bean"/>
      <bean name="my-business-bean-1" depends-on="my-technical-bean"/>
      <bean name="my-business-bean-2" depends-on="my-technical-bean"/>

      It would be better to have something like:

      <bean name="my-technical-bean" init-order="0"/>
      <bean name="my-business-bean-1"/>
      <bean name="my-business-bean-2"/>

      Of course, we could configure several beans with a different initialization order. For example:
      <bean name="my-technical-bean-a" init-order="0"/>
      <bean name="my-technical-bean-b" init-order="1"/>

      Note: "init-order" would be meaningless for lazy-initialized beans.

        Activity

        Hide
        Larry Chu added a comment -

        I think it could be useful to have a way to declare initialization priority without explicitly forcing initialization order, for example we could give a hint to the container than I want X bean initialized as early as possible. This would result in X's dependencies to be initialized, then X would be initialized after the initialization of its dependencies are satisfied.

        The form of this hint could be in a "init-order" attribute on each bean declaration or something similar.

        I think this could particularly be useful in the cases where we don't have explicit control over the bean declaration, for example with custom namespaces. Often times we don't have the ability to declare dependencies from beans created by a custom namespace element.

        See http://forum.springframework.org/showthread.php?p=183445

        Show
        Larry Chu added a comment - I think it could be useful to have a way to declare initialization priority without explicitly forcing initialization order, for example we could give a hint to the container than I want X bean initialized as early as possible. This would result in X's dependencies to be initialized, then X would be initialized after the initialization of its dependencies are satisfied. The form of this hint could be in a "init-order" attribute on each bean declaration or something similar. I think this could particularly be useful in the cases where we don't have explicit control over the bean declaration, for example with custom namespaces. Often times we don't have the ability to declare dependencies from beans created by a custom namespace element. See http://forum.springframework.org/showthread.php?p=183445
        Hide
        Chris Beams added a comment -

        See Phased and SmartLifecycle support introduced in Spring 3.0.

        Show
        Chris Beams added a comment - See Phased and SmartLifecycle support introduced in Spring 3.0.
        Hide
        Benoit Lacelle added a comment - - edited

        Using BeanPostProcessor is another way to provide some ordering in your beans. Check AbstractApplicationContext.refresh() to see how it is enforced.

        Show
        Benoit Lacelle added a comment - - edited Using BeanPostProcessor is another way to provide some ordering in your beans. Check AbstractApplicationContext.refresh() to see how it is enforced.

          People

          • Assignee:
            Chris Beams
            Reporter:
            Bernard Macours
            Last updater:
            Benoit Lacelle
          • Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              7 weeks, 5 days ago