Results 1 to 3 of 3

Thread: Bean Scopes and Business Logic

  1. #1
    Join Date
    Jan 2007
    Location
    Kuala Lumpur, Malaysia
    Posts
    138

    Question 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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  3. #3
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    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).
    Quote 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?

Posting Permissions

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