Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-10311

Reference documentation declares inner beans being prototypes, which is wrong

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.1
    • Fix Version/s: 3.2.2
    • Component/s: [Documentation]
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      The reference documentation on inner beans states inner beans become prototyped beans which is wrong.

      I gave it a quick try and in contrast to what is documented in the section for prototype beans, the inner bean indeed gets destruction callbacks applied. I guess the original statement intended to describe multiple instances being created. But if the bean does not really become a prototype scoped bean we shouldn't use the analogy here.

        Activity

        Hide
        prakash.p Pushkar Prakash added a comment -

        1. This jira gives entire weightage to the destruction Lifecycle callback when deciding what a "prototype" is. why?
        2. Was there any code change done for the jira?

        Show
        prakash.p Pushkar Prakash added a comment - 1. This jira gives entire weightage to the destruction Lifecycle callback when deciding what a "prototype" is. why? 2. Was there any code change done for the jira?
        Hide
        olivergierke Oliver Gierke added a comment - - edited

        1. Prototype beans by definition don't get any destruction callbacks applied. As the documentation stated the beans becoming prototypes a user wasn't expecting them to be invoked, but they were. That caused confusion.
        2. See this commit. There's a section titled "development" on the right here, that gathers these kinds of links.

        Show
        olivergierke Oliver Gierke added a comment - - edited 1. Prototype beans by definition don't get any destruction callbacks applied. As the documentation stated the beans becoming prototypes a user wasn't expecting them to be invoked, but they were. That caused confusion. 2. See this commit . There's a section titled "development" on the right here, that gathers these kinds of links.
        Hide
        prakash.p Pushkar Prakash added a comment -

        1. Prototype scope: If I open the spring documentation (any version), the prototype scope is defined first in terms of its characteristic of multiple instance creation, one instance for each request for the bean. The destruction lifecycle callback is a secondary concept.
        2. Inner beans are (were always) created when the outer is created. N instances of outer will have N instances of inner. This automatically scopes them as prototypes.
        3. If we say inner beans are not prototypes then what is their scope?
        4. The description in this jira says "... the inner bean indeed gets destruction callbacks applied." . This is true only when the enclosing bean is singleton, if the enclosing bean is prototype it does not hold.

        Show
        prakash.p Pushkar Prakash added a comment - 1. Prototype scope: If I open the spring documentation (any version), the prototype scope is defined first in terms of its characteristic of multiple instance creation, one instance for each request for the bean. The destruction lifecycle callback is a secondary concept. 2. Inner beans are (were always) created when the outer is created. N instances of outer will have N instances of inner. This automatically scopes them as prototypes. 3. If we say inner beans are not prototypes then what is their scope? 4. The description in this jira says "... the inner bean indeed gets destruction callbacks applied." . This is true only when the enclosing bean is singleton, if the enclosing bean is prototype it does not hold.

          People

          • Assignee:
            pwebb Phil Webb
            Reporter:
            olivergierke Oliver Gierke
            Last updater:
            Pushkar Prakash
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              41 weeks, 6 days ago