Announcement Announcement Module
Collapse
No announcement yet.
Bean Scopes and Business Logic Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean Scopes and Business Logic

    In a web based spring application, we can set the scopes for the beans.
    Normally a session scope or a request scope. Not setting the scope means that the beans are application scoped.
    Right?

    Ok.
    Moving on.
    When we have business logic inside our codes, what is the scope that we should put our bean?
    Is session scope ok?
    Or is request scope better or is application scope better?
    Why?

    I think we should put it in session scope because if there are a lot of people using the logic, then each person can have their own bean.
    If we put it in the request scope, then we have to re-create the bean over and over again.

    Is this correct?

  • #2
    Your question could not be answered in general. However, your assumption that frequent re-creation of beans is not optimal is correct. So, if the bean in question is not connected to a user, then it should be application-scoped, not session-scoped. That way it needs to be created only once. Besides that it does not litter the session unnecessarily.

    Regards,
    Andreas

    Comment


    • #3
      May you be more specific - which kind of beans do you mean?`which role they play in your application? E.g. if they represent your services, then they should have singleton scope (BTW, the most often used scope).
      Originally posted by titiwangsa View Post
      In a web based spring application, we can set the scopes for the beans.
      Normally a session scope or a request scope. Not setting the scope means that the beans are application scoped.
      Right?

      Ok.
      Moving on.
      When we have business logic inside our codes, what is the scope that we should put our bean?
      Is session scope ok?
      Or is request scope better or is application scope better?
      Why?

      I think we should put it in session scope because if there are a lot of people using the logic, then each person can have their own bean.
      If we put it in the request scope, then we have to re-create the bean over and over again.

      Is this correct?

      Comment

      Working...
      X