Results 1 to 9 of 9

Thread: New bean for every session

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Question New bean for every session

    Hello!
    I have probably stupid question but I do not found answer in the web.

    I need to implement spring bean that will leave only in one session - so, new object will be created for every new session.

    I think it is not a problem to implement it in my own Bean Factory that will acts as singlet, but will contain map for session - object - so, for every session will be used own object, but probably some solution already exists in Spring Core.

    So, may somebody advice anything about this issue?
    Thank you!
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  2. #2
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Question Get Factory instead of Bean

    Hello!
    Another stupid question:

    I have beans like:
    Code:
    <bean id="beanA" class="ClassB">
      <property name="prop1" ref="beanB"/>
    </bean>
    
    <bean id="beanB" class="BeanBFactory">
    </bean>
    For so, beanA expects classA in getProp1
    For beanB I have singleton BeanFactory (BeanBFactory) used for making beanB

    So, by default beanB created then application is initialized and tried to set beanB to beanA.

    But I need to create beanB only then it is really started to be used in beanA - not during application start, but during user working...

    In this case I should set into beanA not beanB - but it's factory - to create object via it then it is required.

    OK, I changed ClassA::setProp1 so, it expects BeanBFactory - but still beanB is created during application initialization

    And only if I remove
    Code:
    implements BeanFactory
    from my BeanBFactory everything started to work.

    So, is it correct solution, or there are some standard pattern exists in Spring for such cases?

    Thank you for any advice
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  3. #3
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Red face Uups, second post I moved to separate thread

    Uups, second post I moved to separate thread
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Maybe you should wait for Spring 2.0RC1 as there is support for bean scoping. The RC1 documentation should also contain information about this.
    RC1 should be available this month. If it's urgent you could also get a nightbuild from CVS.

    Regards,
    Andreas

  5. #5
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Thumbs up Nice to hear

    It is nice to hear and nice to get so fast answer!
    Thank you.

    No, it is not very urgent - anyway I can use some workaround until normal solution from Spring will not be ready
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  6. #6
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Default Session scoped Bean

    Hello! As I found from 2.0-M5 session scoped bean are supported by Spring, but in chapter 4.2.5 of Spring Reference still information about only singleton-not singleton.

    There I can find information about how to create session scoped bean?
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  7. #7
    Join Date
    Oct 2004
    Location
    Fareham, England
    Posts
    313

    Default

    Hi Alexey

    Please do accept my apologies about the lack of documentation surrounding the new scoping support in Spring. The aforementioned scoping support is (or rather was) one of the last things to be finalised for Spring 2.0, and as such I have been waiting for the dust to settle before documenting it.

    If you watch the following JIRA issue you will be able to see when I have finished and committed the documentation.

    http://opensource.atlassian.com/proj...rowse/SPR-1850

    Spring 2.0 is going to be final (famous last words) in time for the SpringOne conference next week, so come hell or high water the docs will be done by then at the very latest. So only a week and a bit to go max

    Cheers
    Rick

  8. #8
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Quote Originally Posted by akakunin
    Hello!
    Another stupid question:

    I have beans like:
    Code:
    <bean id="beanA" class="ClassB">
      <property name="prop1" ref="beanB"/>
    </bean>
    
    <bean id="beanB" class="BeanBFactory">
    </bean>
    For so, beanA expects classA in getProp1
    For beanB I have singleton BeanFactory (BeanBFactory) used for making beanB

    So, by default beanB created then application is initialized and tried to set beanB to beanA.

    But I need to create beanB only then it is really started to be used in beanA - not during application start, but during user working...

    In this case I should set into beanA not beanB - but it's factory - to create object via it then it is required.

    OK, I changed ClassA::setProp1 so, it expects BeanBFactory - but still beanB is created during application initialization

    And only if I remove
    Code:
    implements BeanFactory
    from my BeanBFactory everything started to work.
    Unsure here, but you may want to look at the FactoryBean[1], and search the web for examples of it.

    [1] http://static.springframework.org/sp...le-factorybean

  9. #9
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Default OK, I found how it work

    Rick, no problem
    I already found how it works and during testing found a problem:
    http://opensource.atlassian.com/proj...rowse/SPR-2105

    But problem not very difficult, so, after fixding it everything work perfect!

    Thank you for your job!
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

Posting Permissions

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